[H-GEN] Converting csv file to tab delimited text file

Nick Kwiatkowski nickolas at au1.ibm.com
Wed Jun 7 01:55:03 EDT 2006


Kelvin Heng wrote on 07/06/2006 03:31:22 PM:

> [ Humbug *General* list - semi-serious discussions about Humbug and     ]
> [ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
>
> alright, I guess I have the answer.
>
> All I need to do is:
>
> # sed 's/"//g' sample.csv > sample.txt
> This command will remove all the "
> So my data will be left with only data1,data2,data3,etc
>
> am I right now?
>

Not quite, depending on the data that your application exports as the issue
you will hit is quoting quote characters ie:

John,Doe,120 any st.,"Anytown, WW",08123  as shown at -->
http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm

csv format with the '"' character is used to get around a number of special
characters, including the ',' character. Your above script will break on
that scenario.

you maybe better off looking at the CSV perl module, as it will be complete
--> http://search.cpan.org/~alancitt/Text-CSV-0.01/CSV.pm

Otherwise there are numerous examples of doing this, probably a simple way
would be to grab the csv2tsv.c file from here -->
http://www.sat.dundee.ac.uk/arb/psion/ compile it and let it convert you
files to tab delimited (tsv) format, calling it from your already created
bash script.

Ciao,

Nik

Nickolas Kwiatkowski
IT Architect (Certified)
Architecture Services
Business Consulting Services - Application Services
IBM Global Services, Brisbane, Australia
phone:  07 3213 2149,  mobile:  0412 121 276,  email:  nickolas at au1.ibm.com
"In the middle of difficulty lies opportunity" - Albert Einstein





More information about the General mailing list