I have two files. I want to print data of file1 on the basis of file2.
File1:
a 1
b 2
c 3
d 4
e 1
f 5
g 1
File2:
1 100
2 200
3 400
4 600
5 700
using below command :
awk 'NR==FNR{a[$2]=$1;next}$1 in a{print a[$1] " " $2}' file1 file2
i got following output :
g 100
b 200
c 400
d 600
f 700
But i don't want duplicate values to be overwritten in array . Desired Output :
a 100
e 100
g 100
b 200
c 400
d 600
f 700
Is it possible to store duplicate key in array in awk script like multimap in C++. Or is there another way to do this ? Please help me out.