edit CSV file

April 15, 2011 at 09:32:51
Specs: Windows XP

I need to write a batch file that will remove certain columns in input.csv file and save it as output.csv file

anyone? :s

See More: edit CSV file

Report •

April 15, 2011 at 14:32:44
More info please.

How many columns in original csv file, which columns to be removed, are there any text columns which are csv e.g.

.....,21/12/2011,"21 Some Street, Jackson, Mi. 24029",2367.99,.....

Did you Google for an answer before asking the question?

Report •

April 15, 2011 at 15:13:12
thank you for your quick response.

the csv file has 15 columns, i need to remove column 10, 11, 12, 13 and 14. then the file has to be saved as a csv file with a current date and time in the name. i googled around for solutions but none are relevant. some scripts that i found remove only one column and dont work for multiple columns.

many thanks

Report •

April 15, 2011 at 20:45:54
Try this, not fully tested. You will have to amend the paths/filenames to suit your setup. I suggest you test without changing the path for the output file, leave it in the %temp% folder until you are satisfied the script is doing what you require.

Good luck.

@echo off

:: Get Date & time for output filename
echo WScript.Echo Right(Year(Now^),4^) ^& Right(100+Month(Now^),2^) _
echo ^& Right(100+Day(Now^),2^)

for /f "tokens=*" %%a in (
'cscript.exe //Nologo %temp%\today.vbs') do set today=%%a

del %temp%\today.vbs

set datime=%today%_%time:~0,8%
set datime=%datime::=.%
set  newfile=%temp%\output_%datime%.csv
echo newfile=%temp%\output_%datime%.csv

:: Create new CSV file omitting columns 10 thru' 14 from input file.
for /f "tokens=1-14* delims=," %%A in (%temp%\input.csv) do (
    echo %%A,%%B,%%C,%%D,%%E,%%F,%%G,%%H,%%I,%%O>>%newfile%

Did you Google for an answer before asking the question?

Report •

Related Solutions

April 18, 2011 at 06:45:53
Sorry for my late reply. I tested this script today and it worked perfectly! very clear and does what it's required to do.

Many Thanks!

Report •

April 18, 2011 at 16:38:40
You're welcome, thanks for coming back to report your success.


Did you Google for an answer before asking the question?

Report •

Ask Question