Linux Combine two files by column

前端 未结 4 1390
闹比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:18

    $ awk -v OFS='\t' '
    NR==1   { print $0, "Remark1", "Remark2"; next }
    NR==FNR { a[$1]=$0; next }
    $1 in a { print a[$1], $2, $3 }
    ' Test1.txt Test2.txt
    ID     Name  Telephone  Remark1 Remark2
    1      John     011     Test1   Test2
    2      Sam      013     Test3   Test4
    3      Jena     014     Test5   Test6
    4      Peter    015     Test7   Test8
    

提交回复
热议问题