Reputation: 1
The input.txt file contains 32 records, but only 18 records are processed in output.txt file using this for loop batch script. Any help greatly appreciated!
Code is below (please note that echo >> %stdout% has 50 lines in :process statement not copied here):
@echo off
set "source=C:\test\test\input.txt"
set "stdout=C:\test\test\output.txt"
for /f "tokens=1,2,3,4 delims='" %%a in (%source%) do (
set partner=%%a&set blank=%%b&set comment=%%c&set host=%%d&set
call :process
)
goto :eof
:process
SETLOCAL EnableDelayedExpansion
SET host_final=%host:~1%
echo >> %stdout% partner=%partner% comment=%comment% host=%host_final%
echo >> %stdout% XXXXXXXXXXXXXXXXXXXXXX
....
echo >> %stdout% (line 50 end of %partner%)
ENDLOCAL
goto :eof
Upvotes: 0
Views: 169
Reputation: 38589
I'm not sure what all those lines are that you're echoing, but this is the basic structure I'd recommend:
@Echo Off
Set "source=C:\test\test\input.txt"
Set "stdout=C:\test\test\output.txt"
For /F "UseBackQ EOL=' Tokens=1,3,4 Delims='" %%A In ("%source%"
) Do Call :Process "%%~A" "%%~B" "%%~C"
GoTo :EOF
:Process
Set "host=%~3"
>>"%stdout%" Echo partner=%~1 comment=%~2 host=%host:~1%
GoTo :EOF
As I haven't seen the source file I have to assume that the tokens and delimiters you provided are correct.
Upvotes: 1