This works fine on a 284k text file:
reportFileName = "test.txt"
searchRegExp = /table/
reportFile = File.open reportFileName
anArray = reportFile.grep(searchRegExp)
if anArray.length > 0
puts "#{anArray.length} match(es) found"
# anArray.each { |i| puts i } # uncomment to list matches
else
puts "no matches found"
end
Regards,
JJ
--
Be Kind, Be Careful, Be Yourself
--
Solid, reliable software at reasonable prices
http://www.johnjohnsonsoftware.com
"Phil Tomson" <ptkwt / shell1.aracnet.com> wrote in message
news:xolI6.96$7O2.3495 / typhoon.aracnet.com...
>
> The following bit of code is extracted from a larger chunk of code. It
> basically just opens a file, gets each line and checks to see if a regex
> is satisfied (or a series of regex's in a boolean equation, but in this
> case it's a simple regex). The problem I find is that if the file that is
> being checked is fairly large (in this case it's about 190K bytes) the
> program eventually just stops under Win98 for no good reason. I haven't
> yet tried it on any other platforms, I will try it on Win2000 soon.
>
> I'm wondering if anybody else can try it under Win98 and let me know what
> they get. Of course you'll have to change the file name that's being
> opened and it should be a fairly large file. In the latest run that I did
> of this, it got to iteration 191 and is just sitting there. Also, the
> time between the messages being printed seems to be very non-deterministic
> (sometimes up to a minute between reports, other times less than 20
> seconds). I'm running 1.6.2 in case that matters, and I used the -d flag
> for debug.
>
> Here's the code:
> ####################################################
> i = 0
> while true do
> i += 1
> puts i
> rptFile = "CYPsw00695.rpt" #a 190K text file
> srchStr = "/Error/"
> rpt_h = File.open rptFile
> puts "after File.open #{rptFile}" if $DEBUG
> puts "srchStr is: #{srchStr}" if $DEBUG
> while rpt_h.gets do
> #puts "while: #$_" if $DEBUG
> if eval srchStr
> failed = false
> found = true
> else
> failed = true
> break
> end #if eval
> end
> rpt_h.close
> end
> ###############end###############
>
> Phil
>