行转列

1、#cata.txt

codeAref1

codeBref3

codeArex5

codeBrex2

输出格式为:

codeA

ref:1

rex:5

codeB

rex:2

ref:3

方法一、

cata.txt|sort+0-1+2n|awk'{print$1,$2":"$3}'|awk'{a[$1]=a[$1]?a[$1]"\n"$2:$1"\n"$2}END{for(iina)printa[i]}'

方法二、

catb.txt|sort+0-1+2nr|awk'{print$1,$2":"$3}'|awk'{print$1,$2":"$3}'|awk'{if(!a[$1]++){print$1"\n"$2;}else{print$2}}'

方法三、

catb.txt|sort+0-1+2nr|awk'{print$1,$2":"$3}'|awk'{print$1==i?$2:$1RS$2;i=$1}'

2、行转列

oracle@/opt/oracle/zch:~>cat3.txt

111

222

333

444

555

666

777

oracle@/opt/oracle/zch:~>awk'BEGIN{printf""}{printf$1""}END{printf""}'3.txt

111222333444555666777oracle@/opt/oracle/zch:~>

相关推荐