How to print columns one after the other in bash?

后端 未结 7 1540
感情败类
感情败类 2021-01-14 19:06

Is there any better methods to print two or more columns into one column, for example

input.file

AAA    111
BBB    222
CCC    333

o

7条回答
  •  醉话见心
    2021-01-14 19:14

    Ugly, but it works-

    for i in {1..2} ; do awk -v p="$i" '{print $p}' input.file ; done
    

    Change the {1..2} to {1..n} where 'n' is the number of columns in the input file

    Explanation-

    We're defining a variable p which itself is the variable i. i varies from 1 to n and at each step we print the 'i'th column of the file.

提交回复
热议问题