I need to match two unequal files using $1 of file 1 and $2 of file 2 and print $1 of file 2 on file 1.
Input file 1
101 2
101 5
101 7
103 2
103 3
103 4
105 3
105 2
Input file 2
24 101
23 103
26 105
Desired output
101 2 24
101 5 24
101 7 24
103 2 23
103 3 23
103 4 23
105 3 26
105 2 26
I have tried the following code but it gave me incorrect output.
awk 'FNR==NR{a[$2]=$0;next};{print a[$2]}' file2 file1