But you have to read the file twice. Good luck if the file is 4GB in size and contains about 50M lines.
Reading the whole file into memory is out of the question as well.
I am currently using a Windows PC, the search facility classes large files as 1 MB and huge as 5 MB. I doubt that there is any problem reading such a file into memory.
On my system the txt files are typicay much smaller and this routine works well enough on them.
I admit that the double pass is a small draw back but if you want a professional solution you can download the GNU code and adapt that.
The source is at http://git.savannah.gnu.org/gitweb/?...3b;hb=0482f19. and it's a mere 1700 lines of code!
Bookmarks