From: Michael Greenly Date: 2006-05-03T21:27:29+09:00 Subject: Re: Searching Files Nathan Olberding wrote: > I'm trying to write a simple script to go through all the files in a > specific directory and search for search terms. You should, > hypothetically, be able to run: > > search search_term > # # drop this in a file and run it... it should be fairly easy to adapt this # to what you want # require 'find' search_term = /pear/ Find.find("./") do |path| next unless File.file?(path) File.open(path) do |file| lineno = 0 file.each do |line| lineno += 1 if line =~ search_term puts "#{path}:#{lineno} " + line end end end end __END__ pear apple orange banana kiwi mango -- Posted via http://www.ruby-forum.com/.