Computing.Net > Forums > Programming > Reading data from a file by using batch 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.

Reading data from a file by using batch file

Reply to Message Icon

Name: tomy_usa (by james_usa)
Date: September 17, 2009 at 21:40:23 Pacific
OS: Windows xp
Subcategory: Batch
Comment:

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.




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: September 18, 2009 at 00:25:07 Pacific
Reply:

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


0

Response Number 2
Name: tomy_usa (by james_usa)
Date: September 19, 2009 at 10:48:36 Pacific
Reply:

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


0

Response Number 3
Name: ghostdog
Date: September 19, 2009 at 18:27:19 Pacific
Reply:

if you can download gawk for windows (see my sig)

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

GNU win32 packages | Gawk


0

Response Number 4
Name: Mechanix2Go
Date: September 20, 2009 at 02:28:23 Pacific
Reply:

I checked it before I posted it.

What is in newfile?


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

M2


0

Response Number 5
Name: tomy_usa (by james_usa)
Date: September 20, 2009 at 18:05:36 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: September 21, 2009 at 00:57:54 Pacific
Reply:

I'm not with you. The file name is arbitrary.


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

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Reading data from a file by using batch file

reading data from smart card www.computing.net/answers/programming/reading-data-from-smart-card/7887.html

read data from a file into an array www.computing.net/answers/programming/read-data-from-a-file-into-an-array/11140.html

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