How can I parse CSV files on the Linux command line? [closed] How can I parse CSV files on the Linux command line? [closed] unix unix

How can I parse CSV files on the Linux command line? [closed]


csvtool is really good. Available in Debian / Ubuntu (apt-get install csvtool). Example:

csvtool namedcol Account,Cost input.csv > output.csv

See the CSVTool manual page for usage tips.


My FOSS CSV stream editor CSVfix does exactly what you want. There is a binary installer for Windows, and a compilable version (via a makefile) for UNIX/Linux.


As suggested by @Jonathan in a comment, there is a module for python that provides the command line tool csvfilter. It works like cut, but properly handles CSV column quoting:

csvfilter -f 1,3,5 in.csv > out.csv

If you have python (and you should), you can install it simply like this:

pip install csvfilter

More info at https://github.com/codeinthehole/csvfilter/