Matching data to correct ID from two files in awk

后端 未结 2 1754
耶瑟儿~
耶瑟儿~ 2021-01-16 06:23

I am trying to combine data from two different files. In each file, some data is linked to some ID. I want to \'combine\' both files in the sense that all ID\'s mus

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 07:03

    Does it have to be awk, or did you choose this because you think that's the best - easiest way?

    You can do this via join

    $join -j 1 -a 1 -a 2 -o auto file_1 file_2 | column -t -s' ' -o' '
    1.01 data_a data_aa
    1.02 data_b
    1.03 data_c data_cc
    1.04 data_d
    1.05 data_e data_ee
    1.06 data_f
    1.09        data_ii
    

    edit: As per the excellent suggestion from KamilCuk you can preserve the output afterwards.

提交回复
热议问题