我想使用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.