meg*_*ron 5 unix linux shell cut
我找不到类似的东西,因此发布了这个问题.
假设我有一组提供输出的命令
第一组产生输出
cat xyx.txt | awk '{.........}' | sed 's/.../' | cut -d....
Run Code Online (Sandbox Code Playgroud)
第二组产生输出
cat abc.txt | awk '{.........}' | cut -d ... | sed 's/...../'
Run Code Online (Sandbox Code Playgroud)
我想将这些输出作为"join"命令的2个参数.我知道我可以将这两个文件重定向,然后使用join命令将文件作为参数.
基本上,整个事情可以在一行中完成......就像
[first set of commands] > join -1 1 -2 1 < [second set of commands]
Run Code Online (Sandbox Code Playgroud)
如果您使用bash(许多Linux发行版中的默认shell),则表达式为:
join <([first set of commands]) <([second set of commands])
Run Code Online (Sandbox Code Playgroud)
已验证.
所以
join <(cat xyx.txt | awk '{.........}' | sed 's/.../' | cut -d....) <(cat abc.txt | awk '{.........}' | cut -d ... | sed 's/...../')
Run Code Online (Sandbox Code Playgroud)
应该成功.
$ 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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5760 次 |
最近记录: |