Here's another Text::CSV or Text::CSV_XS version:
perl -MText::CSV -lpe 'BEGIN{$c=Text::CSV->new({always_quote=>1})} $c- +>parse($_); $c->combine($c->fields); $_=$c->string' textfile.csv
...or a little more brief...
perl -MText::CSV -lne 'BEGIN{$c=Text::CSV->new({always_quote=>1})} $c- +>parse($_); $c->print(\*STDOUT,[$c->fields])' textfile.csv
Just substitute "Text::CSV_XS" for Text::CSV if you prefer the XS version, though it's probably not going to make much difference in one-liner world. Watch out for newlines embedded in the input CSV. ;)
An even better one liner would be to convert whichever version like to an actual script, save it in your path somewhere, and then invoke it as:
cat infile.csv | quotecsv > newfile.csv
Dave
In reply to Re: One Liner to double quote every field in a delimited file
by davido
in thread One Liner to double quote every field in a delimited file
by BOK_in_NEPA
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |