1、测试数据
[root@centos79 test]# cat a.txt 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
[root@centos79 test]# cat a.txt 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 [root@centos79 test]# awk '{if(NR % 4 == 0) {print $0} else {printf "%s ", $0}}' a.txt | tee tmp 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 [root@centos79 test]# cat tmp 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
3、对临时文件进行转置
[root@centos79 test]# cat tmp 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 [root@centos79 test]# for i in $(seq $(head -n 1 tmp | awk '{print NF}')); do cut -d " " -f $i tmp | awk '{ORS = " "}{print $0} END {printf "\n"}' >> b.txt; done [root@centos79 test]# cat b.txt 01 05 09 13 17 02 06 10 14 18 03 07 11 15 19 04 08 12 16 20 [root@centos79 test]# cat a.txt 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。