This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Awk merge txt with database based on match

I have a file (file1) with two column (ID and count) as such:

 APH(3'')-Ib 3486552
 mphA 7453
 acrB 6444
 kdpE 4982

and another file (file2) with a list of all the IDs

mphA
APH(3'')-Ib 
cruB
acrB 
kdpE 
vadA

I need to compare the IDs of file1 with the file2: if is present, print the read count. Output desired:

mphA 7453 
APH(3'')-Ib 3486552
cruB 
acrB 6444
kdpE 4982
vadA

I looked at similar question like this but i'm not able to adapt the script to my situation

bash awk card

Sounds like a job for join

1 answer

use join https://linux.die.net/man/1/join

Thanks for the lead, i leave here the command i used for the future

join -a 2 file1 file2 > table

Log in to answer this question.