Wednesday, March 14, 2018

Parsing CSV from bash

In one word csvkit. To install, use python pip and make sure you export the bin path:
pip install --user csvkit
export PATH="$HOME/.local/bin:$PATH"
To extract for instance the second column from clients.csv:
cat clients.csv | csvcut -c 2
An alternative ... csvtool.

To install it in Ubuntu:
sudo apt-get install csvtool
To install it in OS X:
brew install opam
opam init
eval `opam config env`
opam install csvtool
csvtool --help
To extract the second column (index 1) from sample.csv:
cat sample.csv | ~/.opam/system/bin/csvtool col 1 -
Find more from:
~/.opam/system/bin/csvtool --help

2 comments:

Jonathan said...

Thanks!
This line:
opam install csv
Should be:
opam install csvtool

Nestor Urquiza said...

Thanks Johnathan. Fixed.

Followers