{ for (f = 1; f <= NF; f++) { a[NR, f] = $f } }NF > nf { nf = NF }END { for (f = 1; f <= nf; f++) { for (r = 1; r <= NR; r++) { printf a[r, f] (r==NR ? RS : FS) } }}
n 1 2 A 01 02 B 02 02 C 01 01 D 01 01
n A B C D 1 01 02 01 01 2 02 02 01 01
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!