加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何将多个参数传递给unix命令?

发布时间:2020-12-14 01:12:06 所属栏目:Linux 来源:网络整理
导读:我找不到类似的东西,因此发布了这个问题. 假设我有一组提供输出的命令 第一组产生输出 cat xyx.txt | awk '{.........}' | sed 's/.../' | cut -d.... 第二组产生输出 cat abc.txt | awk '{.........}' | cut -d ... | sed 's/...../' 我希望将这些输出作为
我找不到类似的东西,因此发布了这个问题.

假设我有一组提供输出的命令

第一组产生输出

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}') a
1 2 hello hello
2 2 bye bye
3 2 adios ciao

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读