Posted By

evertwh on 03/18/10


Tagged

Bash awk Transpose


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

scilec


transpose rows and columns with awk


 / Published in: Awk
 

  1. #!/usr/bin/awk
  2.  
  3. NR == 1 {
  4. for ( i = 1 ; i <= NF ; i++ ){
  5. line[i] = $i;
  6. }
  7.  
  8. next;
  9. }
  10.  
  11. {
  12. for ( i = 1 ; i <= NF ; i++ ){
  13. line[i] = line[i] OFS $i;
  14. }
  15. }
  16.  
  17. END {
  18. for ( i = 1 ; i <= length(line) ; i++){
  19. print line [i]
  20. }
  21. }

Report this snippet  

You need to login to post a comment.