From: Joel VanderWerf Date: 2010-07-02T02:03:15+09:00 Subject: Re: Fast searching of large files Michael Fellinger wrote: > On Thu, Jul 1, 2010 at 6:47 PM, Stuart Clarke > wrote: >> Hey all, >> >> Could anyone advise me on a fast way to search a single, but very large >> file (1Gb) quickly for a string of text? Also, is there a library to >> identify the file offset this string was found within the file? > > You can use IO#grep like this: > File.open('qimo-2.0-desktop.iso', 'r:BINARY'){|io| > io.grep(/apiKey/){|m| p io.pos => m } } > > The pos is the position the match ended Actually, pos will be the position of the end of the line on which the match was found, because #grep works line by line.