Row to column and column to row using awk

后端 未结 4 1907
小鲜肉
小鲜肉 2020-12-19 00:14

I have two files containing as below

cat file1.txt
a b c 
1 2 3

cat file2.txt
a
b
c
1
2
3

I want file1 to be arranged as

a         


        
4条回答
  •  天命终不由人
    2020-12-19 00:54

    The idiomatic awk approach of simply setting the OFS or ORS to the FS or RS as appropriate before printing (and recompiling the record if necessary with $1=$1) will work with any awk:

    $ cat file1
    a b c
    1 2 3
    $ awk '{OFS=RS;$1=$1}1' file1
    a
    b
    c
    1
    2
    3
    $ cat file2
    a
    b
    c
    1
    2
    3
    $ awk '{ORS=(NR%3?FS:RS)}1' file2
    a b c
    1 2 3
    

提交回复
热议问题