Csv2txt

Up ../

csv2txt — convert a comma separated file to character separated fields

A small program that converts a CSV file into character separated fields. Taking care of quoting and escaping. The code is generalized to allow the definition of the:

As some CSV files include embedded newlines in quoted fields which the -n option will interpolated to the string "\n" by default. Alternative interpolation may be specified with the -N option.

Examples
Running csv2txt explicitly specifying the defaults

csv2txt -D ',' -O '|' -L '"' -R '"' -e '\' myfile.csv
(A)typical input
"Unger, Felix",1972,sitcom,"30 60"
Unger\, Felix,1972,sitcom,30 60
Output
Unger, Felix|1972|sitcom|30 60
Unger, Felix|1972|sitcom|30 60

Source in files/

BUGS
This program scratched an itch when I was sent large excel spreadsheets of accounts with email addresses and was trying to resolve duplicates etc I found it easiest to convert the sheets to CSV (which itself has a rubbery specification) and then to character separated fields with all quoting and escaping removed. Applying unix text tools - cut, paste, sort and join - was the simple part.

That large report spreadsheets contained newline in quoted fields surprised me. The -n and -N options were added to deal with this reasonably sanely.

Converting from the separated field format to csv and then to excel is left as an exercise.

LICENSE
Creative Commons CC0 http://creativecommons.org/publicdomain/zero/1.0/legalcode

AUTHOR
James Sainsbury

SEE ALSO