From: Robert Klemme Date: 2008-08-08T20:07:18+09:00 Subject: Re: Regex. How to return multiple lines 2008/8/8 Damjan Rems : > > I have a text file containing some data. Rows are normaly delimited with > newline char. I assume that file would be read in one chunk into memory. > > Is it possible with regex and how to return all lines containing some > string. > > My first thought was to read file in array and process each line, but I > guess if possible, operating on single string would be faster. 13:07:47 Temp$ ./l.rb ["aaa\n", "a\n", "aaa\n", "a\n"] 13:07:53 Temp$ cat x aaa b c dd a aaa s a 13:07:56 Temp$ cat l.rb #!/bin/env ruby c = File.read "x" p c.grep /a+/ 13:08:49 Temp$ There are of course other possible approaches and depending on what you want to do they might be more efficient. Kind regards robert -- use.inject do |as, often| as.you_can - without end