Match duplicate ids in two files

I have two text files. File 1 has 150 ids but all the ids exists in duplicates so it has 300 ids in total. File 2 has 1500 ids but all exists in duplicates so file 2 has 300 ids in total. i want to match the first occurance of every id in file 1 with first occurance of thet id in file 2 and 2nd occurance of id in file1 with the 2nd occurance of id in file 2. and based upon the value in column 2 print match or mismatch. Looking for an awk sed solution

File1
1 12
1 13
2 15
2 16
4 15 
4 18

File2
1 13
1 13
2 15
2 17
3 12
3 12
4 15 
4 18
5 14
5 14

Desired output (Id, col 2 from file 1, col 2 from file 2, match or mismatch)
1 12 13 mismatch
1 13 13 match
2 15 15 match
2 16 17 mismatch
4 15 15 match
4 18 18 match

Hello limd,

Could you please try following and let me know if this helps you.

 awk 'FNR==NR{A[$1,$2]=$2;B[$1]=$2;next} (($1,$2) in A){print $0,A[$1,$2],"match";next} ($1 in B){print $0,B[$1],"mismatch"}' OFS="\t" Input_file2   Input_file1
 

Thanks,
R. Singh

Try

awk '
NR==FNR         {T1[$1] = T1[$1] $2 FS
                 next
                }
                {T2[$1] = T2[$1] $2 FS
                }
END             {for (t in T1)  {n = split (T1[t], X1)
                                 m = split (T2[t], X2)
                                 for (i=1; i<=n; i++) print t, X1, X2, (X1!=X2?"mis":"") "match"
                                }
                }
' file1 file2
1 12 13 mismatch
1 13 13 match
2 15 15 match
2 16 17 mismatch
4 15 15 match
4 18 18 match