For /f loop findstr problem The batch script finds nothing !!!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PiotrMP006
Posts: 29
Joined: 08 Sep 2017 06:10

For /f loop findstr problem The batch script finds nothing !!!

#1 Post by PiotrMP006 » 23 Dec 2019 06:34

"C:\Program Files\7-Zip\7z.exe" h -scrcsha256 "Test.7z" output:

SHA256 Size Name
---------------------------------------------------------------- ------------- ------------
1D29A48C53E20F5E854FA67A81FFAD7366DF42E507D319CC41FF21E7DE4A4DBC 106 Test.7z
---------------------------------------------------------------- ------------- ------------
1D29A48C53E20F5E854FA67A81FFAD7366DF42E507D319CC41FF21E7DE4A4DBC 106

Size: 106

SHA256 for data: 1D29A48C53E20F5E854FA67A81FFAD7366DF42E507D319CC41FF21E7DE4A4DBC

Everything is Ok

Code: Select all

"C:\Program Files\7-Zip\7z.exe" h -scrcsha256 "Test.7z" | findstr /c:"SHA256 for data"
A command launched from the command line finds this

SHA256 for data: 1D29A48C53E20F5E854FA67A81FFAD7366DF42E507D319CC41FF21E7DE4A4DBC


Code: Select all

for /f "skip=1 tokens=* usebackq" %%a in (`^""C:\Program Files\7-Zip\7z.exe" h -scrcsha256 "Test.7z" ^| findstr "SHA256 for data"^"`) do echo %%a
The batch script finds nothing !!!!

Please help me

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: For /f loop findstr problem The batch script finds nothing !!!

#2 Post by Hackoo » 23 Dec 2019 11:28

I didn't test it yet, but, Perhpas you need to add the command Pause if you execute it by double click ?

Code: Select all

for /f "skip=1 tokens=* usebackq" %%a in (`^""C:\Program Files\7-Zip\7z.exe" h -scrcsha256 "Test.7z" ^| findstr "SHA256 for data"^"`) do echo %%a
pause
Here is another way to get HASH into a variable in batch if you want to use it later :

Code: Select all

@echo off
for /f "tokens=1 usebackq" %%a in (`^""C:\Program Files\7-Zip\7z.exe" h -scrcsha256 "Test.7z" ^| findstr "Test.7z"^"`) do ( 
	set "HASH=%%a"
)
echo %HASH%
pause

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: For /f loop findstr problem The batch script finds nothing !!!

#3 Post by penpen » 24 Dec 2019 19:34

PiotrMP006 wrote:
23 Dec 2019 06:34

Code: Select all

for /f "skip=1 tokens=* usebackq" %%a in (`^""C:\Program Files\7-Zip\7z.exe" h -scrcsha256 "Test.7z" ^| findstr "SHA256 for data"^"`) do echo %%a
The batch script finds nothing !!!!
I tested that batch code and it works?!

Maybe you wanted to add a "/c:" (without doublequotes) like in the sniplet above that for loop:
PiotrMP006 wrote:
23 Dec 2019 06:34

Code: Select all

C:\Program Files\7-Zip\7z.exe" h -scrcsha256 "Test.7z" | findstr /c:"SHA256 for data"
In that case you should note that the "for /f" loop only creates one line that you skip, so it might help to not skip that line:

Code: Select all

for /f "tokens=* usebackq" %%a in (`^""C:\Program Files\7-Zip\7z.exe" h -scrcsha256 "Test.7z" ^| findstr /c:"SHA256 for data"^"`) do echo %%a
penpen

Post Reply