uncsv - convert CSV streams

Fork me on GitHub

uncsv is a filter command converting the lines of a CSV file into non-escaped, non-quoted delimited file (pipe by default). This program will error out if it encounters a character matching the delimiter, it will also replace the carriage return and new-line characters found in quoted values allowing you to use awk to play with your CSVs.

csv is the opposite of this command. It takes an unquoted stream of values, separated by the delimiter of your choice (default: pipe '|') and produces a "standard" CSV file.

Both tools avoid end-of-line character politics and will leave these untouched, if your file comes with both carriage returns and new-line characters (\r\n a.k.a. CRLF), uncsv will leave them as-is.


I've had equivalent python scripts in my ~/bin for a while and decided to translate them in C after losing patience parsing a few terabytes of CSV for work. It's significantly faster but I'd love to hear your comments if you think that could be done better.


# Print the second field of a CSV:
uncsv file.csv | cut -d'|' -f 2

# Convert a CSV to un-quoted tab-delimited format:
uncsv -d'\t' < file.csv > delimited

# Convert a PostgreSQL output to CSV:
psql yourdb
psql> \f\a
psql> \o | csv > /tmp/output.csv
psql> select * from candies;
psql> \o

# Print the first line of the third field.
uncsv -n '~LF~' file.csv | cut -d'|' -f 3 | sed 's/~LF~.*//g'

# Convert your /etc/passwd to CSV.
csv -d: < /etc/passwd

downloads and packages

Latest tarball: uncsv-0.9.1.tar.gz (13K, signature)

GitHub: github.com/tamentis/uncsv/
Arch Linux: https://aur.archlinux.org/packages/uncsv-git/ (thanks to megadriver)
macOS (Homebrew): brew install tamentis/core/uncsv

install from source

$ ./configure
$ make
$ sudo make install

Last updated: 2019-03-02 15:39:28 EST