$ cat file2
this is line 1
this is line 2
this is line 3
this is line 4
this is line 5
this is line 6
this is line 7
this is line 8
this is line 9
this is line 10
$ awk '{printf("%s",$0 (NR%5==0?ORS:":"))}' file2 |awk -F':' '{print $1,$2;print $3,$4,$5}'
this is line 1 this is line 2
this is line 3 this is line 4 this is line 5
this is line 6 this is line 7
this is line 8 this is line 9 this is line 10
我也可以通过以下方式完成工作
paste
:我在这里使用了 bash (for
$'\n'
)。并seq 10
重现您的输入:这在加入和打印 2 或 3 行连续行之间交替。
输出:
或使用原始输入数据:
或者,使用数组。
awk
没有join()
功能,所以我们必须提供一个。只需完成以下工作
awk
:输出:
双 awk 方法:
线首先以五组连接,每条线用
:
符号连接。即使行包含更多单词,解决方案也有效