Linux Combine two files by column

前端 未结 4 1397
闹比i
闹比i 2020-12-14 23:28

I am trying to combine two files as below (Intersection)

ID     Name  Telephone       
1      John     011
2      Sam      013
3      Jena     014
4      Pet         


        
4条回答
  •  长情又很酷
    2020-12-15 00:27

    Another alternative would be pr which is used for formating files to print.

    $ pr -tm -w 50 Test1.txt Test2.txt
    ID     Name  Telephone   ID Remark1  Remark2
    1      John      011     1   Test1    Test2
    2      Sam       013     2   Test3    Test4
    3      Jena      014     3   Test5    Test6
    4      Peter     015     4   Test7    Test8
                             5   Test7    Test8
                             6   Test7    Test8
                             7   Test7    Test8
                             8   Test7    Test8
                             9   Test7    Test8
    

    The most important is the m flag which merges files into columns. The t flag removes headers and footers - since we're not going to print on paper, we don't need them. The last w flag is for setting width.

提交回复
热议问题