?
Solved

FOR /F Tokens script to read first line only.

Posted on 2009-04-09
5
Medium Priority
?
3,509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
Justin_W_Chandler earned 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

752 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