文行行列倒置 转载CU

复制内容到剪贴板
代码:
#!/bin/sh
#ScriptName:rotate
[ $# -ne 1 ] && exit 1
if [ ! -s $1 ]
then
        echo "Usage:rotate datafile"
        exit 1
fi
row=`sed -n '$=' $1`
col=`awk 'NR==1{print NF}' $1`
awk -v row=$row -v col=$col '{for(i=1;i<=NF;i++)a[NR"-"i]=$i} END{ for(i=1;i<=co
l;i++){ for(j=1;j<=row;j++) printf("%s ",a[j"-"i]);printf("\n") } }' $1