- -1: requer python2
- +1: o python2 é mais comum que o csvkit
função drop-in do bash:
function csvgrep(){
grep_criteria="$1"
matchcolumn="$2"
python2 -c "import csv, sys
rows = list(csv.reader(sys.stdin))
writer = csv.writer(sys.stdout)
writer.writerow(rows[0])
for row in rows[1:]:
if row[${matchcolumn}] == '${grep_criteria}':
writer.writerow(row)"
}
Uso:
csvgrep 'valueInLastColumn' '-1' < in.csv > out.csv