Reading data from a file by using batch file

September 17, 2009 at 21:40:23
Specs: Windows xp
hi guys,

The input file is coming like

ddddddd
zzzzzzz
ROW_NUMBER,NAME,SAL
1,aaa,5000

I need to read data from the file from the column name ROW_NUMBER.

Expecting result:

ROW_NUMBER,NAME,SAL
1,aaa,5000

can you guys help me out with any batch file script for doing this.
Any help will be appreciated.



See More: Reading data from a file by using batch file

Report •


#1
September 18, 2009 at 00:25:07
If you need to get the row"ROW_NUMBER,NAME,SAL" and all the rest, try this:

===============
@echo off > newfile & setLocal enableDELAYedexpansion

set S=
for /f "tokens=*" %%a in (myfile) do (
if "%%a" equ "ROW_NUMBER,NAME,SAL" set S=S
if !S! equ S (
>> newfile echo %%a
)
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
September 19, 2009 at 10:48:36
Thanks for ur response

we are able to create a new file but it is not reading the data from the old file..like the below data is not fetching..

ROW_NUMBER,NAME,SAL
1,aaa,5000

Could you please check the code again


Report •

#3
September 19, 2009 at 18:27:19
if you can download gawk for windows (see my sig)

c:\test> gawk -F"," "$1==\"ROW_NUMBER\",0" file

GNU win32 packages | Gawk


Report •

Related Solutions

#4
September 20, 2009 at 02:28:23
I checked it before I posted it.

What is in newfile?


=====================================
Helping others achieve escape felicity

M2


Report •

#5
September 20, 2009 at 18:05:36
The above code is working fine for me. but
The code is based on whole column header like ROW_NUMBER,NAME,SAL

I just want to search based on only one column name ROW_NUMBER,and also my file name is coming like
myfile_yyyymmdd format.means the file name is not coming with fixed name .
Can we read some thing like myfile _ *.* ?

Thanks for ur quick response


Report •

#6
September 21, 2009 at 00:57:54
I'm not with you. The file name is arbitrary.


=====================================
Helping others achieve escape felicity

M2


Report •


Ask Question