It's a question about matrix.


  • 0
    Z
    awk '{
      for (i = 1; i <= NF; i++) {
        a[i, NR] = $i
      }
      if (max_nf < NF) {
        max_nf = NF
      }
    }
    END {
      for(i = 1; i <= max_nf; i++) {
        if(i > 1) {
          print ""
        }
        for(j = 1; j <= NR; j++) {
          if(j > 1)
            printf(" %s", a[i, j])
          else
            printf("%s", a[i, j])
          }
       }
    }' file.txt
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.