-1

I am developing a shell script that executes a command a returns a checksum string. This string is has each hexa separated with white spaces, something that I would like to remove and have, for example, 4AA512, instead of 4A A5 12 as command output but I am not able to find a solution that works. Here the script:

for /f  "delims=" %%f in ('dir %~dp0*.zip /b') do (
    echo %%~f:
    for /f "delims=" %%a in ('certUtil -hashfile "%~dp0%%~f" SHA512 ^| find /i /v "SHA512" ^| find /i /v "certUtil"^') do (
          echo %%a:' '=''%
        )

    set /a counter += 1
    echo.
 )

Anyone has a solution?

Thanks!

  • 1
    Can you post your solution as an answer, so it is more visible to future visitors? – JonathanDavidArndt Oct 15 '18 at 13:27
  • `set "checksum=%~1"` (note: no second `%`) to remove any surrounding quotes (no need for `set checksum=%checksum:"=%`). And yes, please don't put a solution into the question. Make it an answer instead (and accept it). – Stephan Oct 15 '18 at 14:21
  • Take a look at this script on [DosTips.com](https://www.dostips.com/forum/viewtopic.php?t=7592) – Squashman Oct 15 '18 at 14:29
  • Finally got a solution: for /f "delims=" %%f in ('dir %~dp0*.zip /b') do ( echo %%~f: for /f "delims=" %%a in ('certUtil -hashfile "%~dp0%%~f" SHA512 ^| find /i /v "SHA512" ^| find /i /v "certUtil"^') do (call :ShowChecksum "%%a") set /a counter += 1 echo. ) echo %counter% files(s) found. pause exit :ShowChecksum set checksum=%1% set checksum=%checksum: =% set checksum=%checksum:"=% echo %checksum% – user3560080 Oct 17 '18 at 14:32

1 Answers1

1

(answer moved from question/comment to - well - an answer)

Finally got a solution:

set counter=0
for /f  "delims=" %%f in ('dir %~dp0*.zip /b') do (
    echo %%~f:
    for /f "delims=" %%a in ('certUtil -hashfile "%~dp0%%~f" SHA512 ^| find /i /v "SHA512" ^| find /i /v "certUtil"^') do (call :ShowChecksum "%%a")
    set /a counter += 1
    echo.
)

echo %counter% files(s) found.
pause
exit

:ShowChecksum
set "checksum=%~1"
set "checksum=%checksum: =%"
echo %checksum%
Stephan
  • 53,940
  • 10
  • 58
  • 91