Lets sat my file1 is:A   S   B   Qfile2 is:B   2I 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?EditI 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 f2ENSG00000236824.1   AAAAAAAI want to match f2 $1 with f1 $3 and print f1 $0  plus f2 $2I 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 
awk can't print array element
awk
You were almost there. Just change the array index to $1  that is the common element of both files:awk 'NR==FNR {a[$1]=$2;next} $1 in a {print $2, a[$1]}' file2 file1And no idea why you put $1$2 in the array, as you seem to need only $2.Update according to the question edit.You clearly put that match f2 $1 with f1 $3 (I wish every question to be so clear) so just write it in the code accordingly:              f2 $1                             f1 $3                |                                 |awk 'NR==FNR {a[$1]=$2;next} $3 in a {print $0, a[$3]}' f2 f1