I am new to batch scripting and would like to process my input file with the content :
MD5 hash of sample.js,
81f87dd81ef88f59a57d95d9ede5f92e
MD5 hash of searchReplace.js,
3493b216e1024f0d6de417ef6c8b3962
MD5 hash of Select Anything.js,
009f2b911b50550502b87aeeeb969b55
The output should look like :
MD5 hash of sample.js,81f87dd81ef88f59a57d95d9ede5f92e
MD5 hash of searchReplace.js,3493b216e1024f0d6de417ef6c8b3962
MD5 hash of Select Anything.js,009f2b911b50550502b87aeeeb969b55
Can someone please help me out with it ?
CodePudding user response:
try this:
@echo off
setlocal enableDelayedExpansion
set "info_file=.\example1.txt"
for /f "useback tokens=* delims=" %%a in ("%info_file%") do (
set "line=%%a"
if "!line:~0,3!" EQU "MD5" (
set "to_echo=!line!"
) else (
set "to_echo=!to_echo!,!line!"
echo !to_echo!
)
)
endlocal
CodePudding user response:
This works:
@echo off
setlocal
call :procFile < input.txt > output.txt
goto :EOF
:procFile
set /P "line1="
if errorlevel 1 exit /B
set /P "line2="
echo %line1%%line2%
goto procFile
You may also read the file via a for /F
command this way:
@echo off
setlocal EnableDelayedExpansion
set "line="
(for /F "delims=" %%a in (input.txt) do (
if not defined line (
set "line=%%a"
) else (
echo !line!%%a
set "line="
)
)) > output.txt