I want to compare 2nd column of file2 with 1st column of file1. If they are equal i want to add the 2nd column of file1 to file2 as shown in output.txt.
file2
chr5 ENST00000514151 utr5 0 +
chr5 ENST00000512281 utr5 0 +
chr5 ENST00000512281 utr5 0 +
chr5 ENST00000512281 utr5 0 +
file1
ENST00000512281 a
ENST00000504031 b
ENST00000776348 c
output.txt
chr5 a ENST00000512281 utr5 0 +
chr5 a ENST00000512281 utr5 0 +
chr5 a ENST00000512281 utr5 0 +
I was able compare the files with
awk 'NR==FNR{a[$1];next}$2 in a{print}' file1 file2
This gives below output:
chr5 ENST00000512281 utr5 0 +
chr5 ENST00000512281 utr5 0 +
chr5 ENST00000512281 utr5 0 +
But I do not know how to add the 2nd colum of file1 into the output.