答案1
- -1:需要python2
- +1:python2比csvkit更常见
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)"
}
用法:
csvgrep 'valueInLastColumn' '-1' < in.csv > out.csv