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

使用bash将每组N行连接成一行

发布时间:2020-12-15 18:31:05 所属栏目:安全 来源:网络整理
导读:我想使用bash加入另一个命令输出中的每一组N行. 我可以使用任何标准的linux命令来实现这一目标吗? 例: ./command 46.219464 0.000993 17.951781 0.002545 15.770583 0.002873 87.431820 0.000664 97.380751 0.001921 25.338819 0.007437 期望的输出: 46.2
我想使用bash加入另一个命令输出中的每一组N行.

我可以使用任何标准的linux命令来实现这一目标吗?

例:

./command
    46.219464   0.000993    
    17.951781   0.002545    
    15.770583   0.002873    
    87.431820   0.000664    
    97.380751   0.001921    
    25.338819   0.007437

期望的输出:

46.219464   0.000993     17.951781  0.002545
15.770583   0.002873     87.431820  0.000664    
97.380751   0.001921     25.338819  0.007437
如果输出具有一致的字段数,则可以使用xargs -n N对每行的X元素进行分组:
$...command... | xargs -n4
46.219464 0.000993 17.951781 0.002545
15.770583 0.002873 87.431820 0.000664
97.380751 0.001921 25.338819 0.007437

来自man xargs:

-n max-args,–max-args=max-args

Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded,unless the -x option is given,in which case xargs will exit.

(编辑:李大同)

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

    推荐文章
      热点阅读