如何将多个参数传入unix命令?

我找不到任何类似的东西,因此张贴的问题。

说我有一套提供输出的命令

第一组产生输出

cat xyx.txt | awk '{.........}' | sed 's/.../' | cut -d.... 

第二套产生输出

 cat abc.txt | awk '{.........}' | cut -d ... | sed 's/...../' 

我想把这些输出作为2个参数给“join”命令。 我知道我可以redirect这两个文件,然后使用连接命令与文件作为参数。

基本上,整个事情可以做在一个单一的线….类似的东西

 [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