Inserting a column into a CSV file

Microsoft Windows 7 professional 64-bit
April 2, 2010 at 02:13:02
Specs: Windows 7
I would like to add a column to a CSV file so I can use the data with eSignal which is a stock charting program.

The CSV file is in the following format Date,Time,Price,Volume. It does not have a header. For example here is a test.csv

100401,090037,0.9838,1,
100401,090058,0.9839,1,
100401,090100,0.9839,9,

I would like the data changed so it reads T,Date,Time,Price,Volume. For example.

T,100401,090037,0.9838,1,
T,100401,090058,0.9839,1,
T,100401,090100,0.9839,9,

Any suggestions would be greatly appreciated. I tried doing this in excel and word but the files are 300mb so it wouldn't work.


See More: Inserting a column into a CSV file

Report •


#1
April 2, 2010 at 04:44:36
download sed for windows and then on command line
sed -i.bak "s/^/T,/" file.csv

GNU win32 packages | Gawk


Report •

#2
April 2, 2010 at 06:38:18
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (my.csv) do (
>> newfile echo.T,%%a
)


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

M2


Report •

#3
April 2, 2010 at 07:40:28
Thank you for your speedy replies! Both methods worked flawlessly. The sed program took about 30secs to create the file, whereas the batch file took 30mins.

Report •

Related Solutions

#4
April 2, 2010 at 07:52:42
Thanks for the update. I was curious about how long it would take on a big file.


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

M2


Report •

#5
April 2, 2010 at 08:07:14
@M2, OP is not processing other columns, just adding something to the front. you can omit the tokens and delims. it should be a bit faster. (it will not be as fast as a dedicated tool for file parsing since the algorithm for parsing is compiled)

GNU win32 packages | Gawk


Report •


Ask Question