Robert Klemme
3/11/2006 12:55:00 PM
Nathan Olberding <nathan.olberding@gmail.com> wrote:
> I want to search all the files in a directory for a string and save
> the results in an Array. So far, the best solution I can come up with
> is using system("grep ... > resultsFile"), then opening resultsFile
> and doing readlines(). There's a better way, isn't there?
# untested
found = {}
Dir["/foo/*"].each {|f| found[f] = File.open(f) {|io|
io.grep(/your_string/)} }
This should give you a hash with file names as keys and match lines as
values.
Kind regards
robert