如何将两个管道传输到 shell 脚本?

如何将两个管道传输到 shell 脚本?

如何从文件中剪切选定的列。

例子:

load.sh students.csv | select.sh ‘name’ ‘school_name’ 

这会将加载的文件中的名称和 school_name 列输出到终端。

答案1

使用csvcutcsvsql来自csvkit:

csvcut -c name,school_name students.csv
csvsql --query 'select name, school_name from students' students.csv

例子:

$ cat students.csv
id,name,surname,school_name,favorite_color
1,Tom,Sawyer,Harvard,red
2,Bob,"the Builder",Oxford,orange
3,John,Sinclair,"Columbine High",blue
4,Walter,Mitty,"Thomas Jefferson High",green
5,Donald,Trump,Unknown,blue

$ csvcut -c name,school_name students.csv
name,school_name
Tom,Harvard
Bob,Oxford
John,Columbine High
Walter,Thomas Jefferson High
Donald,Unknown

相关内容