5/25/2022

print one column after another

 guofyuan @ htpvis-025a$ cat test.txt
AAA    111  123
BBB    222  234
CCC    333  345

guofyuan @ htpvis-025a$ awk '{if(maxc<NF)maxc=NF; for(i=1;i<=NF;i++){(a[i]!=""?a[i]=a[i]RS$i:a[i]=$i)} } END{for(i=1;i<=maxc;i++)print a[i]}' test.txt
AAA
BBB
CCC
111
222
333
123
234
345

 

 gawk '{for (i=1; i<=NF; i++) # loop over columns

           data[i][NR]=$i               # store in data[column][line]
      }
      END {for (i=1;i<=NR;i++)          # loop over lines
                for (j=1;j<=NF;j++)     # loop over columns
                     print data[i][j]   # print the given field
      }' file

https://stackoverflow.com/questions/39287224/how-to-print-columns-one-after-the-other-in-bash

没有评论: