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

前端之家收集整理的这篇文章主要介绍了使用bash将每组N行连接成一行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用bash加入另一个命令输出中的每一组N行.

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

例:

  1. ./command
  2. 46.219464 0.000993
  3. 17.951781 0.002545
  4. 15.770583 0.002873
  5. 87.431820 0.000664
  6. 97.380751 0.001921
  7. 25.338819 0.007437

期望的输出

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

猜你在找的Bash相关文章