Computing.Net > Forums > Programming > batch app read line from a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch app read line from a file

Reply to Message Icon

Name: duckkiller53
Date: February 25, 2009 at 12:52:48 Pacific
OS: Windows server 2003
Subcategory: Batch
Comment:

Is there a way to have a batch app open a file and read a line into a variable.

ie:

batchapp.bat
------------

open datafile

var=read(datafile)

echo var



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: February 25, 2009 at 20:51:19 Pacific
Reply:

This will read the first line into var:

for /f "tokens=*" %%q in (datafile) do (
set var=%%q 
goto :eof
) 

this will read the last line into var
 for /f "tokens=*" %%q in (datafile) do set var=%%q  

this will read the 12th Line:
 
for /f "skip=11 tokens=*" %%q in (datafile) do (
set var=%%q 
goto :eof
)

--
Holla.


0

Response Number 2
Name: Mechanix2Go
Date: February 25, 2009 at 23:13:24 Pacific
Reply:

Hi Holla,

For the first line you can simplify it to:

set /p var=<datafile


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: Holla
Date: February 26, 2009 at 00:53:19 Pacific
Reply:

Thanks M2,

Everyday is a learning.
The more I learn, the less I know.

--
Holla.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch app read line from a file

reading lines from text file (java) www.computing.net/answers/programming/reading-lines-from-text-file-java/12276.html

read from a file... Fortran or C www.computing.net/answers/programming/read-from-a-file-fortran-or-c/576.html

Read lines from .txt file in DOS? www.computing.net/answers/programming/read-lines-from-txt-file-in-dos/15219.html