A simple CSV extractor.
Sometimes, I need to process too large CSV files from command-line. Needless to say, we have great tools such as cat
, sed
, grep
and awk
.
cat /path/to/csv-file | awk -F ',' '{ print $2 "," $1 }'
However, how I can specify columns by column name, instead of column number like $1
or $2
?
Although I didn't google it, I didn't have clear answer(s) to achieve.
So I created csvv.
go get github.com/tacahiroy/csvv
go build csvv.go
csvv /path/to/csv column1,column2[,column3...]
Here's a CSV file, say users.csv
.
id,name,email,github,twitter
1,Bob,[email protected],bobaaa,bob123
2,Jake,[email protected],jakeaaa,jake123
If you want to get fields named id
and email
, you may run like this:
csvv users.csv id,email
Then you get:
id,email
1,[email protected]
2,[email protected]