merge two files based on common column values

前端 未结 2 1055
清酒与你
清酒与你 2021-01-26 00:26

I have file1 likes:

1 A aa
2 A bb
3 A cc
4 A dd
5 B xx
6 C yy
7 C zz

And a file2:

1 A 11
2 B 22
3 C 33

And I

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-26 01:01

    Which way is the simplest

    I am not sure what do you mean by simplest. For this problem, you can simply use join:

    join -j 2 -o 1.1 1.2 1.3 2.3 file1 file2
    

    For the given example, the above command generates the desired output. If your file is not sorted, you can also add --nocheck-order option.

提交回复
热议问题