From: Daniel Berger Date: 2003-06-24T23:50:10+09:00 Subject: Re: Operate on a range of lines in a file. Robert Klemme wrote: > "Brian Candler" schrieb im Newsbeitrag > news:20030624075527.GC57124@uk.tiscali.com... > >>On Tue, Jun 24, 2003 at 11:02:58AM +0900, Jim Bob wrote: >> >>>I'm hoping someone can jog my memory here. Say I've got a file which >>>contains the keywords "START" and "END", with several lines in >> > between. > >>>Suppose I want to operate on everything between START and END >> > (inclusive > >>>or not, doesn't really matter, I don't think). Read in paragraph mode. Set $/ to "END". # Sample source file: # test.txt START This is some text This is some more text foo END START bar baz blahblahblah END START Last paragraph Hello World END # Sample source # paratest.rb file = "test.txt" $/ = "END" n = 0 IO.foreach(file){ |para| print "\nPARA #: #{n}\n" puts "=========" puts para n += 1 } # Sample output >ruby paratest.rb PARA #: 0 ========= START This is some text This is some more text foo END PARA #: 1 ========= START bar baz blahblahblah END PARA #: 2 ========= START Last paragraph Hello World END PARA #: 3 ========= You may need to deal with the last element properly. Regards, Dan