matching columns from two files

Hey,

I have two files that have exactly the same format. They are both tab-delimited and contain 12 columns. However the # of rows vary. What I want to do is match columns # 5,6 and 7 between the two files. If they do match exactly (based on numbers) then I want the whole row from file 2 to be transfered to another file.

Heres an example

File1

Y  K  R  I  5  8  2  HERMESRY  OP  TUI  1  P

File2

Y  K  R  I  5  8  2  HERNEST  OP  TUI  1  P
Y  K  R  I  4  10  1  HERNESO  PP  TUI  1  P

New file

Y  K  R  I  5  8  2  HERNEST  OP  TUI  1  P

Because 5, 8 and 2 were a match between the two files then the entire row is moved to a new file. The file that I have literally has a 100 million rows so obviously I cannot do it by eye.

Thank you

Phil

Here is what I have, using awk:

awk 'NR==FNR{A[$5$6$7]=1;next}A[$5$6$7]' f1 f2 > f3

f1 and f2 are your two input files, f3 is the output file