2011年6月13日星期一

unix - transpose a file

here, some scripts on transposing file, row to colums

http://stackoverflow.com/questions/1729824/transpose-a-file-in-bash

I find this awk way is helpful to me.

#############################################
awk '
{ 
    for (i=1; i<=NF; i++)  {
        a[NR,i] = $i
    }
}
NF>p { p = NF }
END {    
    for(j=1; j<=p; j++) {
        str=a[1,j]
        for(i=2; i<=NR; i++){
            str=str" "a[i,j];
        }
        print str
    }
}' file

没有评论:

发表评论