Compare rows in 2 files

Hi all

I have a file A and a file B and for each line of file B I would like to read all those of file B, test if field X of file B contains field X of file A and if so append field X to file A.

How can I do it?

Thanks in advance