Link to home
Start Free TrialLog in
Avatar of ZabagaR
ZabagaRFlag for United States of America

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
ASKER CERTIFIED SOLUTION
Avatar of Justin_W_Chandler
Justin_W_Chandler
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZabagaR

ASKER

Thank you.  The only correction I had to make was my own really, I have to put %%i (and for the other VARs too) in a batch script. Need double percent signs instead of single.
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

Open in new window

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
Avatar of ZabagaR

ASKER

Thanks.  I appreciate it!!!