?

Log in

No account? Create an account

Previous Entry | Next Entry

Transpose of a matrix : BASH way of doing

A one liner for generating of a transpose of a matrix.


$ echo -  | awk '{print "1\t2\t3\n4\t5\t6\n7\t8\t9\n"}'
1       2       3
4       5       6
7       8       9

$ echo -  | awk '{print "1\t2\t3\n4\t5\t6\n7\t8\t9\n"}' | awk '{for(j=1;j<=NF;j++){arr[j]=arr[j]"\t"$j}} END {for(i in arr) print arr[i]}' | sed 's/^\t//'
1       4       7
2       5       8
3       6       9

Profile

jaduks
Jadu Kumar Saikia

Latest Month

January 2008
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  
Powered by LiveJournal.com
Designed by chasethestars