From: pat eyler Date: 2009-05-15T05:44:10+09:00 Subject: Re: Can you get the 1st occurrence of a value using grep? lines.detect {|l| l =~ /fail/} On Thu, May 14, 2009 at 2:30 PM, Mmcolli00 Mom wrote: > Can you get a 1st occurence of a sting inside a huge text file? > > For instance, I  know that there will be 1 or more occurrences of a the > string 'fail' in a text file and I only want to get the first line > containing the 'fail' instead of getting every line with a fail. My > program reads over 100 files that may contain one or more 'fail' values. > > Thanks > MC > > Dir["//MYFile/*.txt"].each do |textfile| >    getGrepOffense = textfile.grep(/fail/) >    strOffense = getGrepOffense.join >    puts strOffense > end > -- > Posted via http://www.ruby-forum.com/. > > -- thanks, -pate ------------------------- Don't judge those who choose to sin differently than you do http://on-ruby.blogspot.com http://eldersjournal.blogspot.com