batch app read line from a file

February 25, 2009 at 12:52:48
Specs: Windows server 2003
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


See More: batch app read line from a file

Report •


#1
February 25, 2009 at 20:51:19
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.


Report •

#2
February 25, 2009 at 23:13:24
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


Report •

#3
February 26, 2009 at 00:53:19
Thanks M2,

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

--
Holla.


Report •

Related Solutions


Ask Question