in reply to merging content based on common columns of 2 files using grep
Have a look at Corion's most excellent join - join two files according to a common key. Sounds like it will do exactly what you want.
HTH,