Answer» Hi,
I need a help in writing a small batch program(read.bat) in windows 2003 which reads a set of values from a file.
The OUTPUT of the file is below.
file: list.txt
Name Path
A1 C:\ A2 D:\ A3 E:\ A4 F:\
From the above output all the values under the column one "Name" , except the column name has to be set to a variable. this value is used in some other place in the script.
Please help me in writing the script.
Thanks in advance Raghu A
Is this what you wanted? It displays: A1 A2 A3 A4
This batch would be NICER if you would TAKE out the part with the Name and Path because I had to program it to skip that line. This one took me awhile. I didn't THINK this was possible in batch. This was made in XP 64-bit so don't know if it will work in 2003.
Code: [Select]echo off setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (B:\list.txt) do ( set /a N+=1 if !N! GTR 1 ( set /a I+=1 set tmpvar=%%a set var!I!=!tmpvar:~0,2! ) )
echo !var1! echo !var2! echo !var3! echo !var4!
Quote from: Linux711 on July 16, 2009, 01:16:02 AM Is this what you wanted? It displays: A1 A2 A3 A4
This batch would be nicer if you would take out the part with the Name and Path because I had to program it to skip that line. This one took me awhile. I didn't think this was possible in batch. This was made in XP 64-bit so don't know if it will work in 2003.
Code: [Select]echo off setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (B:\list.txt) do ( set /a N+=1 if !N! GTR 1 ( set /a I+=1 set tmpvar=%%a set var!I!=!tmpvar:~0,2! ) )
echo !var1! echo !var2! echo !var3! echo !var4!
Instead of using set /a N+=1 to skip a line, use skip=1 between tokens and delims.
|