第一次在这里发帖,所以请温柔一点。我试图在一个混乱的文件中找到一个 URL 末尾的字符串,这个文件包含各种格式的东西,\n\t\t\t<p>
这使得找到正确的字符串变得delims
很棘手。
我的数据文件看起来完全像这样:
href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19950_en_1\" managed-link=\"\" target=\"\">Get Wolf Resting image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19641_en_1\" managed-link=\"\" target=\"\">Get Provence Chalk-hill Blue Butterfly image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19975_en_1\" managed-link=\"\" target=\"\">Get Japanese Fox image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19091_en_1\">Get Clown Fish image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19044_en_1\">Get Buzzing Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19245_en_1\">Get Flamingo image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19042_en_1\">Get Butterfly in Yellow Flowers image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19064_en_1\">Get Cattle Under Stormy Sky image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19188_en_1\">Get Dragonfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19449_en_1\">Get Ladybug on Flower Petal image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19645_en_1\">Get Puppy with a Leaf image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19688_en_1\">Get Red Lacewing Butterfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19273_en_1\">Get Fuzzy Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>
这是我的代码:
for /F "tokens=16 delims=asset-blobs/" %%a in ('findstr /I "https://kbdevstorage1.plot.core.candles.net/asset-blobs/" mydata.txt') do set "imageid=%%aen_1"
echo Image ID is: %imageid%
我所追求的是 URL 末尾的字符串资产 blob/例如19950_en_1从第一场比赛开始19641_en_1从第二个开始,依此类推。
我的问题:
- 循环
for
不循环。 - 我没有捕获干净的字符串,所以我必须附加en_1找到后,将其添加到字符串中。这部分没什么大不了的,我可以忍受。
当我运行批处理文件时,仅得到 1 个(第一个)匹配项,然后它就停止了。
请帮助我了解我做错了什么。我不想使用 VBscript 或其他任何东西,如果可能的话,只使用本机 Windows 命令。
我对脚本编写完全是新手,但我正在努力学习。谢谢。
答案1
据我理解,电源外壳解决方案是:
$data = Get-Content 'c:\folder\capture.txt'
($data -split 'asset-blobs/').substring(0,10)
输出
PS C:\...\keith>($data -split 'asset-blobs/').substring(0,10)
href=\"htt
19950_en_1
19641_en_1
19975_en_1
19091_en_1
19044_en_1
19245_en_1
19042_en_1
19064_en_1
19188_en_1
19449_en_1
19645_en_1
19688_en_1
19273_en_1
为了消除第一个元素并仅返回前导数字,我们可以使用:
($data -split 'asset-blobs/').ForEach({ If ( $_ -match '(^\d+)') { $Matches[0] }})
输出:
PS C:\> ($data -split 'asset-blobs/').ForEach({ If ( $_ -match '(^\d+)') { $Matches[0] }})
19950
19641
19975
19091
19044
19245
19042
19064
19188
19449
19645
19688
19273
答案2
- 更新
电源外壳可以使用一行来完成此操作,并且无需在批处理文件中转义任何特殊字符:
(Get-Content "G:\data\file.txt").split("/\") | Select-String '^[0-9]'
- 或者使用别名
Get-Content == gc
和 :Select-String == sls
(gc "G:\data\file.txt").split("\/")|sls '^[0-9]'
# or...
(gc "G:\data\file.txt").split("/\")|sls '^[0-9]'
@echo off
(findstr /b .g "%~f0"|Powershell -c - ) >"%tmp%\ps_outs.txt"
type "%tmp%\ps_outs.txt" & goto :EOF
(gc "G:\data\file.txt").split("\/")|sls '^[0-9]'
- 或者...
@echo off
(findstr /b .g "%~f0"|Powershell -c - ) & type "G:\data\ps_outs.txt" & goto :EOF
(gc "G:\data\file.txt").split("/\")|sls '^[0-9]'|Out-File -FilePath "G:\data\ps_outs.txt"
- 输出:
19950_en_1
19641_en_1
19975_en_1
19091_en_1
19044_en_1
19245_en_1
19042_en_1
19064_en_1
19188_en_1
19449_en_1
19645_en_1
19688_en_1
19273_en_1
更新/end
- 如果使用 PowerShell 批处理是可以接受的,那么就尝试一下...
; @echo off
;
; setlocal EnableDelayedExpansion
; set "_out_puts=%temp%\!randon!_list_line_out.txt"
; cd.>nul>"!_out_puts!" && cd.>nul>"%temp%\string_temp_list.log"
;
; for /f tokens^=* %%i in ('2^>nul "%windir%\system32\where.exe" /r "%windir%" "powershell.exe"
; ')do >>"%temp%\string_temp_list.log" ("%__APPDIR__%findstr.exe" -rbv ; "%~dpnx0"|"%%~dpnxi" -c - ) && goto :continue
$_lines = Get-content "G:\this folder\data\mydata.txt";
$_lines.Replace('\" managed-link=\"\" target=\"',' \').Replace('asset-blobs/',"""`r`n""").Replace('</a>','\\').Replace('\">',' ').Replace('\\',' ').Replace('"','').Replace("_?"," ").Replace(' \ ',' ')|Out-String|scb;Get-Clipboard
;
; :continue
; for /f tokens^=1delims^=^< %%i in ('
; type "%temp%\string_temp_list.log"^|"%windir%\system32\findstr.exe" /rb [0-9]*\_[a-z]*
; ')do echo/%%~i && set /a "_cnt+=1+0" && call set "_str_!_cnt!=%%~i"
;
; for /l %%L in (1 1 !_cnt!)do call echo/id: !_str_%%L:~0,10! name: !_str_%%L:~10!>>"!_out_puts!"
; type "!_out_puts!"|C:\Windows\System32\clip.exe
;
; echo\ & echo\Image lines strings variables: _str_1 to _str_!_cnt!
; echo\Images listed in outputs on file: "!_out_puts!" & endlocal
; "%windir%\system32\timeout.exe" -1 & goto :eof
- 文件内容:
- 该文件的前两个和最后两个,用此布局中的 9 行进行了测试
\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19950_en_1\" managed-link=\"\" target=\"\">Get Wolf Resting image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19641_en_1\" managed-link=\"\" target=\"\">Get Provence Chalk-hill Blue Butterfly image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19975_en_1\" managed-link=\"\" target=\"\">Get Japanese Fox image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19091_en_1\">Get Clown Fish image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19044_en_1\">Get Buzzing Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19245_en_1\">Get Flamingo image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19042_en_1\">Get Butterfly in Yellow Flowers image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19064_en_1\">Get Cattle Under Stormy Sky image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19188_en_1\">Get Dragonfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19449_en_1\">Get Ladybug on Flower Petal image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19645_en_1\">Get Puppy with a Leaf image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19688_en_1\">Get Red Lacewing Butterfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19273_en_1\">Get Fuzzy Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>
\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19951_en_2\" managed-link=\"\" target=\"\">Get Wolf Resting image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19641_en_2\" managed-link=\"\" target=\"\">Get Provence Chalk-hill Blue Butterfly image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19975_en_2\" managed-link=\"\" target=\"\">Get Japanese Fox image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19091_en_2\">Get Clown Fish image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19044_en_2\">Get Buzzing Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19245_en_2\">Get Flamingo image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19042_en_2\">Get Butterfly in Yellow Flowers image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19064_en_2\">Get Cattle Under Stormy Sky image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19188_en_2\">Get Dragonfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19449_en_2\">Get Ladybug on Flower Petal image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19645_en_1\">Get Puppy with a Leaf image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19688_en_2\">Get Red Lacewing Butterfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19273_en_2\">Get Fuzzy Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>
....
\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19956_en_7\" managed-link=\"\" target=\"\">Get Wolf Resting image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19641_en_7\" managed-link=\"\" target=\"\">Get Provence Chalk-hill Blue Butterfly image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19975_en_7\" managed-link=\"\" target=\"\">Get Japanese Fox image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19091_en_7\">Get Clown Fish image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19044_en_7\">Get Buzzing Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19245_en_7\">Get Flamingo image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19042_en_7\">Get Butterfly in Yellow Flowers image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19064_en_7\">Get Cattle Under Stormy Sky image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19188_en_7\">Get Dragonfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19449_en_7\">Get Ladybug on Flower Petal image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19645_en_1\">Get Puppy with a Leaf image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19688_en_7\">Get Red Lacewing Butterfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19273_en_7\">Get Fuzzy Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>
\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19957_en_8\" managed-link=\"\" target=\"\">Get Wolf Resting image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19641_en_8\" managed-link=\"\" target=\"\">Get Provence Chalk-hill Blue Butterfly image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a data-content-id=\"\" data-content-type=\"\" href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19975_en_8\" managed-link=\"\" target=\"\">Get Japanese Fox image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19091_en_8\">Get Clown Fish image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19044_en_8\">Get Buzzing Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19245_en_8\">Get Flamingo image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19042_en_8\">Get Butterfly in Yellow Flowers image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19064_en_8\">Get Cattle Under Stormy Sky image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19188_en_8\">Get Dragonfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19449_en_8\">Get Ladybug on Flower Petal image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19645_en_1\">Get Puppy with a Leaf image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19688_en_8\">Get Red Lacewing Butterfly image</a></p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t<p><a href=\"https://kbdevstorage1.plot.core.candles.net/asset-blobs/19273_en_8\">Get Fuzzy Bee image</a></p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p>
- 输出:
19950_en_1 Get Wolf Resting image
19641_en_1 Get Provence Chalk-hill Blue Butterfly image
19975_en_1 Get Japanese Fox image
19091_en_1 Get Clown Fish image
19044_en_1 Get Buzzing Bee image
19245_en_1 Get Flamingo image
19042_en_1 Get Butterfly in Yellow Flowers image
19064_en_1 Get Cattle Under Stormy Sky image
19188_en_1 Get Dragonfly image
19449_en_1 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_1 Get Red Lacewing Butterfly image
19273_en_1 Get Fuzzy Bee image
19951_en_2 Get Wolf Resting image
19641_en_2 Get Provence Chalk-hill Blue Butterfly image
19975_en_2 Get Japanese Fox image
19091_en_2 Get Clown Fish image
19044_en_2 Get Buzzing Bee image
19245_en_2 Get Flamingo image
19042_en_2 Get Butterfly in Yellow Flowers image
19064_en_2 Get Cattle Under Stormy Sky image
19188_en_2 Get Dragonfly image
19449_en_2 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_2 Get Red Lacewing Butterfly image
19273_en_2 Get Fuzzy Bee image
19952_en_3 Get Wolf Resting image
19641_en_3 Get Provence Chalk-hill Blue Butterfly image
19975_en_3 Get Japanese Fox image
19091_en_3 Get Clown Fish image
19044_en_3 Get Buzzing Bee image
19245_en_3 Get Flamingo image
19042_en_3 Get Butterfly in Yellow Flowers image
19064_en_3 Get Cattle Under Stormy Sky image
19188_en_3 Get Dragonfly image
19449_en_3 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_3 Get Red Lacewing Butterfly image
19273_en_3 Get Fuzzy Bee image
19953_en_4 Get Wolf Resting image
19641_en_4 Get Provence Chalk-hill Blue Butterfly image
19975_en_4 Get Japanese Fox image
19091_en_4 Get Clown Fish image
19044_en_4 Get Buzzing Bee image
19245_en_4 Get Flamingo image
19042_en_4 Get Butterfly in Yellow Flowers image
19064_en_4 Get Cattle Under Stormy Sky image
19188_en_4 Get Dragonfly image
19449_en_4 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_4 Get Red Lacewing Butterfly image
19273_en_4 Get Fuzzy Bee image
19953_en_4 Get Wolf Resting image
19641_en_4 Get Provence Chalk-hill Blue Butterfly image
19975_en_4 Get Japanese Fox image
19091_en_4 Get Clown Fish image
19044_en_4 Get Buzzing Bee image
19245_en_4 Get Flamingo image
19042_en_4 Get Butterfly in Yellow Flowers image
19064_en_4 Get Cattle Under Stormy Sky image
19188_en_4 Get Dragonfly image
19449_en_4 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_4 Get Red Lacewing Butterfly image
19273_en_4 Get Fuzzy Bee image
19954_en_5 Get Wolf Resting image
19641_en_5 Get Provence Chalk-hill Blue Butterfly image
19975_en_5 Get Japanese Fox image
19091_en_5 Get Clown Fish image
19044_en_5 Get Buzzing Bee image
19245_en_5 Get Flamingo image
19042_en_5 Get Butterfly in Yellow Flowers image
19064_en_5 Get Cattle Under Stormy Sky image
19188_en_5 Get Dragonfly image
19449_en_5 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_5 Get Red Lacewing Butterfly image
19273_en_5 Get Fuzzy Bee image
19955_en_6 Get Wolf Resting image
19641_en_6 Get Provence Chalk-hill Blue Butterfly image
19975_en_6 Get Japanese Fox image
19091_en_6 Get Clown Fish image
19044_en_6 Get Buzzing Bee image
19245_en_6 Get Flamingo image
19042_en_6 Get Butterfly in Yellow Flowers image
19064_en_6 Get Cattle Under Stormy Sky image
19188_en_6 Get Dragonfly image
19449_en_6 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_6 Get Red Lacewing Butterfly image
19273_en_6 Get Fuzzy Bee image
19956_en_7 Get Wolf Resting image
19641_en_7 Get Provence Chalk-hill Blue Butterfly image
19975_en_7 Get Japanese Fox image
19091_en_7 Get Clown Fish image
19044_en_7 Get Buzzing Bee image
19245_en_7 Get Flamingo image
19042_en_7 Get Butterfly in Yellow Flowers image
19064_en_7 Get Cattle Under Stormy Sky image
19188_en_7 Get Dragonfly image
19449_en_7 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_7 Get Red Lacewing Butterfly image
19273_en_7 Get Fuzzy Bee image
19957_en_8 Get Wolf Resting image
19641_en_8 Get Provence Chalk-hill Blue Butterfly image
19975_en_8 Get Japanese Fox image
19091_en_8 Get Clown Fish image
19044_en_8 Get Buzzing Bee image
19245_en_8 Get Flamingo image
19042_en_8 Get Butterfly in Yellow Flowers image
19064_en_8 Get Cattle Under Stormy Sky image
19188_en_8 Get Dragonfly image
19449_en_8 Get Ladybug on Flower Petal image
19645_en_1 Get Puppy with a Leaf image
19688_en_8 Get Red Lacewing Butterfly image
19273_en_8 Get Fuzzy Bee image
Image lines strings variables: _str_1 to _str_117
Images listed in outputs on file: "C:\Users\ecker\AppData\Local\Temp\_list_line_out.txt"
Press any key to continue...
1)使用 PowerShell 混合批处理来分隔以;
使用批处理会话和 PowerShell 使用的常规会话:
; echo/ line/code Batch Session
write-host line/code PowerShell Session
2)设置环境场景和此过程所需的所有变量:
; @echo off
;
; setlocal EnableDelayedExpansion
; set "_out_puts=%temp%\!randon!_list_line_out.txt"
; cd.>nul>"!_out_puts!" && cd.>nul>"%temp%\string_temp_list.log"
3)实施for
循环过滤批本身,所有不以;
并在运行时重定向到电源外壳(在这种情况下为两行),它们将在那里执行,完成后转到标签:continue...
; for /f tokens^=* %%i in ('2^>nul "%windir%\system32\where.exe" /r "%windir%" "powershell.exe"
; ')do >>"%temp%\string_temp_list.log" ("%__APPDIR__%findstr.exe" -rbv ; "%~dpnx0"|"%%~dpnxi" -c - ) && goto :continue
$_lines = Get-content "G:\this folder\data\mydata.txt";
$_lines.Replace('\" managed-link=\"\" target=\"',' \').Replace('asset-blobs/',"""`r`n""").Replace('</a>','\\').Replace('\">',' ').Replace('\\',' ').Replace('"','').Replace("_?"," ").Replace(' \ ',' ')|Out-String|scb;Get-Clipboard
; :continue
4)项目中的两行 PowerShell 代码3将在第一行定义/操作你的长变量,但第二行将替换/删除一些字符串和一些字符/字符串,以便通过转换成类似的行使其更具可读性,其中可以每行应用一个正则表达式来提取一些过滤后的字符串为了循环,结果大致如下:
\https://kbdevstorage1.plot.core.candles.net/
19950_en_1 Get Wolf Resting image<+ ... varuius charater..../
19641_en_2 Get Provence Chalk-hill Blue Butterfly image<+ ... varuius charater..../
19975_en_8 Get Japanese Fox image<+ several more characters..../
19091_en_9 Get Clown Fish image<+ several more characters..../
19044_en_0 Get Buzzing Bee image<+ several more characters..../
5)使用 for 循环提取所有字符<
在每一行开头处:[0-9]*_[a-z]*_
,并设置增量以将每一行保存在变量中:!_str_cnt!++
; for /f tokens^=1delims^=^< %%i in ('
; type "%temp%\string_temp_list.log"^|"%windir%\system32\findstr.exe" /rb [0-9]*\_[a-z]*
; ')do echo/%%~i && set /a "_cnt+=1+0" && call set "_str_!_cnt!=%%~i"
6)只是一个代码示例,展示如何使用!_str_cnt!++
可递增变量来检索值/行For /L
环形。
- 观察:这也将放置整个
!_Out_puts!
文件中包含Crtl+C
(剪贴板),如有必要,粘贴到您需要的地方,只是一个建议,在我编码/测试这个脚本时非常有用,如果不需要它,只需删除...
; for /l %%L in (1 1 !_cnt!)do echo/!_str_%%L!>>"!_out_puts!"
; type "!_out_puts!"|C:\Windows\System32\clip.exe
7)最后,一些关于工作/过程的结果的信息...以及时间限制,如果您不需要的话。
; echo\ & echo\Image lines strings variables: _str_1 to _str_!_cnt!
; echo\Images listed in outputs on file: "!_out_puts!" & endlocal & goto :EOF
; "%windir%\system32\timeout.exe" -1
- PowerShell 行:
$_lines = Get-content "G:\this folder\data\mydata.txt";
$_lines.Replace('\" managed-link=\"\" target=\"',' \').Replace('asset-blobs/',"""`r`n""").Replace('</a>','\\').Replace('\">',' ').Replace('\\',' ').Replace('"','').Replace("_?"," ").Replace(' \ ',' ')|Out-String|scb;Get-Clipboard
- 注意:您需要设置文件的完整路径
mydata.txt
$_lines = Get-content "G:\Full\Path\To\Your\Data\File\MyData.txt"
基于/受以下信息启发:
阅读更多:
- 抱歉我的英语水平有限……