ZabagaR
asked on
FOR /F Tokens script to read first line only.
I'm currently using the line below in a batch script to find data in a text file.
for /f "tokens=3,4,5,6" %i in (myfile.txt) do @echo %i %j %k %l
The data (or columns) I want (3,4,5,6) are only from the 1st line of text in my input file myfile.txt.
My script will read the entire file and I'll end up with way more output than I need. I'd like to just scan the first line in my file for the data then exit. What do I need to do?
-thanks!
Bob
for /f "tokens=3,4,5,6" %i in (myfile.txt) do @echo %i %j %k %l
The data (or columns) I want (3,4,5,6) are only from the 1st line of text in my input file myfile.txt.
My script will read the entire file and I'll end up with way more output than I need. I'd like to just scan the first line in my file for the data then exit. What do I need to do?
-thanks!
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can add a GOTO command to skip to a label after it reads the first line.
for /f "tokens=3,4,5,6" %i in (myfile.txt) do (
@echo %i %j %k %l
goto :_next
)
:_next
REM rest of script here
SHIFT-3 the other way is just to do this:
for /f "tokens=3,4,5,6" %i in (myfile.txt) do @echo %i %j %k %l & goto :eof
for /f "tokens=3,4,5,6" %i in (myfile.txt) do @echo %i %j %k %l & goto :eof
ASKER
Thanks. I appreciate it!!!
ASKER