 <p>When data became too big to fit memory, the only way is use extended memory (HDD). Here you can partition and store on disk, load small part each onto memory and search.</p> <p>Or you should use a algobrithm that use less memory and more processor. <br>1.Search the file, search all num, and create a relative 2-d matrix or something like below. </p> <pre><code> 1 2 3 4 ... 1 0 1 0 0 2 0 1 0 0 3 0 0 0 0 ... </code></pre> <p><br>2.You can sort on this matrix. <br>3.One by one pair, search the file to get line num contain both numbers in pair.<br> Sorry because my bad english.</p>