1.

Solve : need a help to create a batch file?

Answer»

Hi folks,
I am newbie to MS-Dos.

Can you please help me out in creating a batch file to read a data from each listing CSV files as follows:

1.to list a all the CSV files.
2.read the data from each CSV file one by one.



it's urgent.
Dir *.csv

will list all your csv files

Dir /s *.csv

will list all csv files in the current directory and in sub directories

What do you MEAN by read ? youcan display them to the screen and view them if thats what you meanEach CSV file contains many column.
I want to read column 2nd and 3rd and store the value in some variable.

And i think we need to put the CSV file listing in a loop and read the 2nd and 3rd column value of every CSV file and store it in a some variable.


Hope you gotta know what i mean to say.

Thanks for ur reply


in batch, you can use a for loop, put delimiter as comma and then go on from there. Read for /? from the command LINE to know more, or search the forum for example CODE. there's lots.
however if you are not restrained to use batch, you can use text processing tools like gawk, for example

Code: [Select]gawk "{print $2,$5}" file

or if you want something native, with vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFile= "C:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
splitted = Split(strLine,",")
WScript.Echo splitted(2) , splitted(4)
Loop

the above solutions are not working.

Can anyone help me out with batch fileQuote from: chandrakala on March 20, 2009, 03:57:27 AM

Each CSV file contains many column.
I want to read column 2nd and 3rd and store the value in some variable.
Quote from: chandrakala on March 23, 2009, 02:41:22 AM
the above solutions are not working.

Can anyone help me out with batch file
huh? where is ghostdog?

the vbs solution is working. except to read column 2 and 3, you change the echo line to this:
Code: [Select]WScript.Echo splitted(1) , splitted(2)Quote from: Reno link=topic=79348.msg525766#msg525766 date=1237970543where is ghostdog?
[/quote
still here. just not going to waste my time asking back what's not working.
Study this, and hopefully all will become clear

Code: [Select]@echo off
echo column 1, column 2, column 3, column 4, column 5> test.csv
echo cat, dog, 12.445, Monday January 1st 2009, Zaragoza>> test.csv
echo Ant, Bear, "Chicken", "Diana Smith", Egg Sandwich>> test.csv

set filename=test.csv
for /f "tokens=1-5 delims=," %%A in ( ' type "%filename%" ' ) do (
echo %%B,%%C
)


Code: [Select]column 2, column 3
dog, 12.445
Bear, "Chicken"
Hi ghostdog,
The code is working fine.Thanks for you help.
Sorry could not reply you early due to some reason.sorry again.

Thank you for your help and time


Discussion

No Comment Found