How to transpose a table of data using awk

Hi.

I have this data below:-
v1 28 14 1.72414 1.72414 1.72414 1.72414 1.72414
v2 77 7 7.47126 6.89655 6.89655 6.89655 6.89655
v3 156 3 21.2644 21.2644 20.6897 21.2644 20.6897
v4 39 3 1.72414 1.72414 1.72414 1.72414 1.72414
v5 155 1 21.2644 23.5632 24.1379 23.5632 24.1379
v6 62 2 2.87356 4.02299 4.02299 2.87356 4.02299
v7 152 4 20.6897 20.6897 20.6897 20.6897 20.6897
v8 154 1 22.4138 22.4138 22.4138 22.4138 22.4138

and I wanted to transpose them to be:-

v1 v2 ..........v8
28 77
14 .7
1.72414 7.47126
1.72414 6.89655
1.72414 6.89655
1.72414 6.89655

Please advise. Thanks

Taken from the GNU AWK handbook:

{
if (max_nf < NF)
max_nf = NF
max_nr = NR
for (x = 1; x <= NF; x++)
vector[x, NR] = $x
}

 END \{
      for \(x = 1; x &lt;= max_nf; x\+\+\) \{
           for \(y = max_nr; y &gt;= 1; --y\)
                printf\("%s ", vector[x, y]\)
           printf\("\\n"\)
      \}
 \}

Copy that to a file, then invoke it like this:

awk -f scriptfile datafile | awk '{ print $8"\t" $7"\t" $6"\t" $5"\t" $4"\t" $3"\t" $2"\t" $1"\t" }'

A perl script to transpose a metrix, hope it can address your issue.

$file=shift;
open(FH,"<$file") or die "can not open file";
while(<FH>){
        $_=~ tr/\n//d;
        @arr=split(",",$_);
        $col=$#arr;
        for($i=0;$i<=$#arr;$i++){
                $index=sprintf("%s%s",$.,$i);
                $hash{$index}=$arr[$i];
        }
        $row=$.;
}
close(FH);
for($a=0;$a<=$col;$a++){
        for($b=1;$b<=$row;$b++){
                $t=sprintf("%s%s",$b,$a);
                print $hash{$t},",";
        }
        print "\n";
}