awk行转列

  sre
[root@node01 ~]# cat test
a b c
1 2 3
4 5 6
[root@node01 ~]# awk '{for(i=1;i<=NF;i++)a[NR,i]=i}END{for(j=1;j<=NF;j++)for(k=1;k<=NR;k++)printf k==NR?a[k,j] RS:a[k,j] FS}' test
a 1 4
b 2 5
c 3 6
[root@node01 ~]# cat test |awk '{for(i=0;++i<=NF;)a[i]=a[i]?a[i] FSi:$i}END{for(i=0;i++<NF;)print a[i]}'
a 1 4
b 2 5
c 3 6

LEAVE A COMMENT

Captcha Code