unix: merge files based on column value

后端 未结 1 573
感动是毒
感动是毒 2020-12-21 09:16

I have two files, that look like this:

File 1 (2 columns):

ID1 123
ID2 234
ID3 232
ID4 344
...

File 2 (>1 million columns)

相关标签:
1条回答
  • 2020-12-21 10:04
    $ join <(sort file1) <(sort file2)
    ID1 123 C T ...
    ID2 234 A C ...
    ID3 232 G T ...
    ID4 344 A C ...
    

    If you want keep the order of file2

    $ join -1 1 -2 2 <(sort file1) <(cat -n file2 | sort -k2,2) | sort -k3,3n | cut -d' ' -f1-2,4-
    ID2 234 A C ...
    ID3 232 G T ...
    ID1 123 C T ...
    ID4 344 A C ...
    
    0 讨论(0)
提交回复
热议问题