Solved

FOR /F Tokens script to read first line only.

Posted on 2009-04-09
5
3,430 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:ZabagaR
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
Justin_W_Chandler earned 500 total points
ID: 24108579
for /f "tokens=3,4,5,6" %i in (myfile.txt) do @echo %i %j %k %l >> %temp%\asdf.tmp
set /p var_FirstLine=<%temp%\asdf.tmp
echo %var_FirstLine%
0
 
LVL 15

Author Closing Comment

by:ZabagaR
ID: 31568560
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.
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24108757
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

0
 
LVL 6

Expert Comment

by:Justin_W_Chandler
ID: 24108921
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
0
 
LVL 15

Author Comment

by:ZabagaR
ID: 24111381
Thanks.  I appreciate it!!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now