I have been searching in the forum a solution for my problem but unfortunately I was not successful. I am quite green in bash; therefore I would really appreciate any suggestion ot link to previous question/discussions
I have two files:
file1
Ada ada
Ada ada
Ada aidB
Ada alkA
Ada alkB
Ada alkB
AdiY adiA
AdiY gadA
file2
NP_414557.1 insL1
NP_414559.1 mokC
YP_025292.1 hokC
NP_414560.1 nhaA
NP_414561.1 nhaR
NP_414562.1 insB1
NP_414563.1 insA
NP_414564.1 rpsT
I would like to compare file1 and file2 based on the second column. If the object is the same I would like to append the text in the column 1 in file2 relative to that specific shared entry in a third column in file1.
Expected output: file1
PhoB caiT NP_414580.1
PhoP caiE NP_414581.1
PhoP caiB NP_414582.1
Please consider the text reported just as example.
I am struggling with awk trying to adjust the code from a previouse question:
Compare two files of different columns and print different columns
awk 'NR==FNR{a[$1]=$2 ; next }$2 in a {$1=$1 FS a[$2]print}' file1 file2
Thank you very much in advance for your time and your help.
Best.