transpose rows and columns with awk


/ Published in: Awk
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.