For this kind of job, join is very useful. While using join keep in mind that both file are sorted on column, which are identiticalidentical in both files.
Here is the solution
sort -o file1 file1 #sort and save content of file1
Sortsort -o file2 file2 #sort and save content of file2
join file1 file2