D
David Ashe
I am trying to take lines from a file, and split the contents into 4 files,
first line to the first file, 2nd to the second, etc. but the fifth line
goes back into the first file. (Actually, just the 4th token, not the whole
line) I am using a counter (creatively named "counter") to decide where the
line goes however, I am getting unexpected results. I Expect to get a
round-robin of VALUE:1, VALUE:2,..., and the final "End Counter" being
between 1 and 4. However, The Final End Counter is equal to the number of
lines in the file, and I get VALUE:1, over and over.
It is definitely some kind of scope issue, but I don't know how to fix it.
------- Begin Script ---------------
set COUNTER=1
for /f "tokens=1-4" %%A in (%1) do (
if %COUNTER% EQU 1 (
echo VALUE:1
) else if %COUNTER% EQU 2 (
echo VALUE:2
) else if %COUNTER% EQU 3 (
echo VALUE:3
) else if %COUNTER% EQU 4 (
echo VALUE:4
set COUNTER=1
)
set /a COUNTER+=1
)
echo.
echo End Counter: %COUNTER%
first line to the first file, 2nd to the second, etc. but the fifth line
goes back into the first file. (Actually, just the 4th token, not the whole
line) I am using a counter (creatively named "counter") to decide where the
line goes however, I am getting unexpected results. I Expect to get a
round-robin of VALUE:1, VALUE:2,..., and the final "End Counter" being
between 1 and 4. However, The Final End Counter is equal to the number of
lines in the file, and I get VALUE:1, over and over.
It is definitely some kind of scope issue, but I don't know how to fix it.
------- Begin Script ---------------
set COUNTER=1
for /f "tokens=1-4" %%A in (%1) do (
if %COUNTER% EQU 1 (
echo VALUE:1
) else if %COUNTER% EQU 2 (
echo VALUE:2
) else if %COUNTER% EQU 3 (
echo VALUE:3
) else if %COUNTER% EQU 4 (
echo VALUE:4
set COUNTER=1
)
set /a COUNTER+=1
)
echo.
echo End Counter: %COUNTER%