From: Dave Thomas Date: 2003-12-16T07:29:09+09:00 Subject: Re: Extracting multiple lines from a file On Dec 15, 2003, at 16:16, Ron Coutts wrote: > file = File.open("ordinal") > while file.gets > print if /third/ .. /fifth/ > End > > Unfortunately this code snippet is buggy as it prints out all ten lines > of the file, not just lines three through five as mentioned in the > book. > Yeah - Ruby 1.8 changed this. You could try file = File.open("ordinal") while line = file.gets print if line =~ /3/.. line =~ /5/ end If the file is a reasonable size, if might be easier to do content = File.read("ordinal") content.scan(/^START(.*?)^END/m) do |match,| p match end This reads in the whole file, then calls the block passing in the chunks of it between START and END. Cheers Dave Cheers Dave