将将一个文本的奇数行和偶数行合并
[root@summer ~]# cat johb.txt
11111111111111
22222222222222
33333333333333
44444444444444
55555555555555
[root@summer ~]# sed 'N;s#\n# #g' johb.txt
11111111111111 22222222222222
33333333333333 44444444444444
55555555555555
2. xargs默认使用的是空格为分隔符,通过-d指定新的分隔符,这里修改为\n回车换行 为分隔符。-n2表示以回车为换行符后,我要每行显示两列,也就是两行。
[root@summer ~]# xargs -d "\n" -n2 < johb.txt
11111111111111 22222222222222
33333333333333 44444444444444
55555555555555
3. 当前行是奇数行时执行line=$0,将整行赋值给line,next跳过其余的命令
[root@summer ~]# awk 'NR%2==1{line=$0;next}{print line,$0}' johb.txt
11111111111111 22222222222222
33333333333333 44444444444444
4. awk判断奇偶行并显示
[root@summer ~]# awk '{if(NR%2==0) print $0;else printf $0 " "}' johb.txt
11111111111111 22222222222222
33333333333333 44444444444444
55555555555555 [root@summer ~]#
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有