I am trying to create a batch file to read a text file line by line, and then create a separate file for each line.
I first tried the following, which gives the correct file for the last line only:
@echo off
set ncount=0
FOR /F %%a IN (data_input.txt) DO (set testvar=%%a
set /a ncount+=1 )
echo %testvar% > "data_output%ncount%.txt"
I have also tried the following, which gives the correct files (data_output1.txt, data_output2.txt, etc) though does not pass the line text into the file (they all show "ECHO is off"
)
@echo off
set ncount=1
FOR /F %%a IN (data_input.txt) DO (set testvar = %%a
set /a ncount+=1
call :sub1
)
goto :eof
:sub1
echo %testvar% > "data_output%ncount%.txt"
What am I doing wrong?