You’re not limited to keeping the tokens in the order in which they appear in the input file. You can, for example, display the tokens in reverse order with the command
For /f "tokens=1,2,3,4,5,6,7,8,9,10" %i in (C:\testdata.txt)
Do Echo %r %q %p %o %n %m %l %k %j %i
You can even display the tokens in a comma-separated format with a command such as
For /f "tokens=1,2,3,4,5,6,7,8,9,10" %i in (C:\testdata.txt)
Do Echo %i,%j,%k,%l,%m,%n,%o,%p,%q,%r
As I discussed in "Shell Scripting 101, Lesson 4," you can redirect the For /f command’s output to a file by adding the >> redirection symbol:
For /f "tokens=1,2,3,4,5,6,7,8,9,10" %i in (C:\testdata.txt) Do Echo
%i,%j,%k,%l,%m,%n,%o,%p,%q,%r>>C:\testreport1.txt
Experimenting with the delims Option
In the command-shell window, run the command
Echo 10,100,55,23 > C:\testdata2.txt
to create the file testdata2.txt on your C drive. Now, run the commands
For /f "tokens=1,2,3,4" %i in (C:\testdata2.txt) Do Echo %i %j %k %l
For /f "tokens=1,2,3,4 delims=," %i in (C:\testdata2.txt) Do Echo %i %j %k %l