when you say, 'not manually' I assume you mean not by going into the contact entry & tapping on the link button because there are too many of them?
Doesn't facebook & gmail have some sort of contact import function on one or the other's website? Maybe you can use that?
Also, gmail website has some contact duplication management functions in it. maybe you can fix it there?