[lug] awk question

Tkil tkil at scrye.com
Mon Jan 27 19:44:37 MST 2003


>>>>> "James" == James Harris <Harris> writes:

James> Kinda stumped here.  I have a .csv file that I need to parse
James> (using awk, preferably) that uses quotes to protect "real"
James> commas in the data.

Not in awk, but there's a standard module that comes with perl to do this:

   perl -MText::ParseWords=quotewords \
     -lnwe 'print join "|", quotewords ",", 0, $_' foo.csv

There's a faq on dealing with CSV files in perl:

   http://www.perldoc.com/perl5.8.0/pod/perlfaq4.html#How-can-I-split-a-%5bcharacter%5d-delimited-string-except-when-inside%0a%5bcharacter%5d--(Comma-separated-files)

t.



More information about the LUG mailing list