Sort the files first, then it's easy.
In reply to Re: Faster grep in a huge file(10 million) by thewebsi in thread Faster grep in a huge file(10 million) by Thomas Kennll