[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

FOR /F Tokens script to read first line only.

Posted on 2009-04-09
5
Medium Priority
?
3,553 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 …
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 video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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