From: Shashank Date Date: 2006-04-28T07:35:55+09:00 Subject: Re: getting the next line with the iterator --0-1659381608-1146177352=:333 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit How about reading the enire file in an array, something like (untested code): arr = IO.readlines('toto.txt') list = [] arr.each_with_index{|line,i| if line =~ /regExp/ list << line[i] list << line[i+1] list << line[i+2] end } This may not work as is, but will give you an idea ... HTH, -- shanko Eric Boucher wrote: Hi, I would like to know if there is a ruby way to achieve what I want to do. I want to be able to access the next iterator while reading a file. Basically, I want to be able to collect the next 3 lines when I encounter a certain line: list = [] File.open('toto.txt', 'rb') do |myFile| myFile.each {|line| if line =~ /regExp/ list << line.nextIterator list << line.nextIterator list << line.nextIterator end } end puts list This code is not working, I know. The method "nextIterator" doesn't exist. This is the way I see it, but I don't know how to do it. I think that you can invode the method "next" on iterators in Python. I don't know how to do that without invoking the command 'next' with a flag and a counter, a little bit like this code (which is not very rubyist): list = [] flagIn = false counter = 3 File.open('toto.txt', 'rb') do |myFile| myFile.each {|line| if line =~ /regExp/i flagIn = true next end if flagIn list << line counter -= 1 flagIn = false if counter == 0 end } end puts list Any suggestions? Thanks -- Posted with http://DevLists.com. Sign up and save your mailbox. --------------------------------- New Yahoo! Messenger with Voice. Call regular phones from your PC and save big. --0-1659381608-1146177352=:333--