linux 中awk脚本实现文本转置

 

001、

[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt              ## 测试文本
01      02      03      04      05
06      07      08      09      10
11      12      13      14      15
16      17      18      19      20
21      22      23      24      25
26      27      28      29      30
[root@pc1 test]# awk '{for(i=1; i<=NF; i++) {a[i] = (a[i]?a[i]"\t"$i:$i)}}END{for(i=1; i <= length(a); i++) {print a[i]}}' a.txt        ## awk实现文本转置
01      06      11      16      21      26
02      07      12      17      22      27
03      08      13      18      23      28
04      09      14      19      24      29
05      10      15      20      25      30

 

image

。 

 

posted @ 2025-11-13 23:50  小鲨鱼2018  阅读(3)  评论(0)    收藏  举报