Solved

FOR /F Tokens script to read first line only.

Posted on 2009-04-09
5
3,455 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 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