Lets sat my file1 is:
A S
B Q
file2 is:
B 2
I want to match $1 from file2 with $1 file1 and print file1 $2 && file2 $2, for the output like this:
Q 2
My awk solution is:
awk 'NR==FNR {a[$1]=$1$2;next} $1 in a {print $2, a[$2]}' file2 file1
And it gives me only Q - it doesn't print array's second element.
How can I print array's element?
Edit
I updated my question as the answer that works for dummy example doesn't work with my actual data.
f1
chr2 47558199 ENSG00000236824.1
chr2 47558199 ENSG00000236824.1
chr2 47558199 ENSG00000236824.1
f2
ENSG00000236824.1 AAAAAAA
I want to match f2 $1 with f1 $3 and print f1 $0 plus f2 $2
I tried this answer awk 'NR==FNR {a[$1]=$2;next} $3 in a {print $0, a[$1]}' f2 f1,
but still not getting the output I want.
awk code above gets me only this:
chr2 47558199 ENSG00000236824.1
chr2 47558199 ENSG00000236824.1
chr2 47558199 ENSG00000236824.1