[英]How can I pipe multiple arguments into a unix command?
我找不到类似的东西,因此发布了这个问题。
假设我有一组提供输出的命令
第一组产生输出
cat xyx.txt | awk '{.........}' | sed 's/.../' | cut -d....
第二组产生输出
cat abc.txt | awk '{.........}' | cut -d ... | sed 's/...../'
我想将这些输出作为“join”命令的2个参数。 我知道我可以将这两个文件重定向,然后使用join命令将文件作为参数。
基本上,整个事情可以在一行中完成......就像
[first set of commands] > join -1 1 -2 1 < [second set of commands]
如果您使用bash(许多Linux发行版中的默认shell),则表达式为:
join <([first set of commands]) <([second set of commands])
已验证。
所以
join <(cat xyx.txt | awk '{.........}' | sed 's/.../' | cut -d....) <(cat abc.txt | awk '{.........}' | cut -d ... | sed 's/...../')
应该成功。
$ cat a
1 hello
2 bye
3 ciao
$ cat b
1 hello 123
2 bye 456
3 adios 789
$ cut -d' ' -f1,2 b | awk '{print $1, 2, $2}'
1 2 hello
2 2 bye
3 2 adios
$ join <(cut -d' ' -f1,2 b | awk '{print $1, 2, $2}') a
1 2 hello hello
2 2 bye bye
3 2 adios ciao
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.