Batch script to find a string in a messy file and loop until all strings found

First post here so please be gentle. I am trying to find a string which is at the end of a URL in a messy file that contains all kinds of formatting stuff like \n\t\t\t<p> which makes finding the correct delims tricky.

My data file looks exactly like this:

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>    

Here is my code:

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%

What I am after is the string at the end of the URL after asset-blobs/ for example 19950_en_1 from the first match and 19641_en_1 from the second, and so on.

My problems:

  1. The for loop does not loop.
  2. I am not capturing a clean string so I have to append en_1 to the string after I find it. This part is no big deal I can live with it.

When I run the batch file I get only 1 (the first) match and it stops.

Please help me understand what I am doing wrong. I don't want to use VBscript or anything else, just native Windows commands if possible.

I'm a total newb to scripting but I am trying to learn. Thank you.


Solution 1:

As I understand the question, the PowerShell solution would be:

$data = Get-Content 'c:\folder\capture.txt'
($data -split 'asset-blobs/').substring(0,10)

Output

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

To eliminate the first element & return only the leading digits, we can use:

($data -split 'asset-blobs/').ForEach({ If ( $_ -match '(^\d+)') { $Matches[0] }})

Output:

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

Solution 2:

  • Update

powershell can do it using a line and you don't need to escape any special characters in batch file:

(Get-Content "G:\data\file.txt").split("/\") | Select-String '^[0-9]'

  • Or using aliases Get-Content == gc and : Select-String == sls

(gc "G:\data\file.txt").split("\/")|sls '^[0-9]'

# or... 
(gc "G:\data\file.txt").split("/\")|sls '^[0-9]'

  • Just save as file.bat and run this hybrid file batch/powershell code:
@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]'
  • Or...
@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"
  • Output:
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

Update /end


  • If using a batch with PowerShell is acceptable try, so give a try...
;   @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
  • File content:
    • The first two of the file and the last two, tested with 9 lines in this layout
\"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>
  • Outputs:
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) Use a hybrid batch with PowerShell delimiting all lines starting with ; to use the batch session and a normal one to be used by PowerShell:

;   echo/ line/code Batch Session
    write-host line/code PowerShell Session

2) Set environment scenario and all variable you will need need for this process:

;   @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) Implement a for loop to filter in the batch itself, all lines that do not start with ; and that will be redirected at runtime to powershell (two lines in this case), where they will be executed, and when finished go to label :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) Two PowerShell lines in item 3 will define/manipulate your long variable on the 1st line, but the second will replace/remove some strings and some characters/strings, in order to make it more readable by transforming into similar lines, where it is possible to apply a regex line per line to extract some filtered strings in a for loop, resulting in more or less like this:

\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) Use the for loop to extract all characters up to < on each line where it starts with: [0-9]*_[a-z]*_, with an increment set to save each line in a variable: !_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) Just a code example showing how to use the !_str_cnt!++ incrementable variable to retrieve a value/line in the For /L loop.

  • Obs.: This will also place a copy of the entire !_Out_puts! file contained in your Crtl+C (ClipBoard), paste where you need, if necessary, just a suggestion, very useful wend i coding/testing this script, if dont need it, just remove...
;   for /l %%L in (1 1 !_cnt!)do echo/!_str_%%L!>>"!_out_puts!"
;   type "!_out_puts!"|C:\Windows\System32\clip.exe

7) Finally, some information about the result of the work/process ... and a time limit, if you don't need cut too.


;   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:
$_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
  • Note: You need set the full path to your file mydata.txt
$_lines = Get-content "G:\Full\Path\To\Your\Data\File\MyData.txt"

enter image description here


Based/inspired by information from:

  • Hybrid Bat-PS1: From Walid2me answer

  • Relace Strings: From Sam Boutros answer

  • Escaping Characters in PowersShell: From Wiktor Stribiżew answer

Read more:

  • Replace

  • Slect-String | slc

  • Get-Content | gc | cat

  • Set-Clipboard

  • Get-Clipboard

  • EOL End Of Line

  • Line Break: LF, CR and CRLR

- I'm sorry for my limited English...