From: "Jesús Gabriel y Galán" Date: 2012-06-23T00:41:46+09:00 Subject: Re: Reading only certain rows of data from a text file On Fri, Jun 22, 2012 at 5:37 PM, Jason Peterson wrote: > Hi Everyone, > My name is Jay, I'm new to the forum as well as fairly new to Ruby. I am > writing a program with File.open to read a text file, however need help > on a code that would only read certain rows of this large file. I am > basically only trying to get the rows where the first column has 'cdtr' > (example) > in the data field. > > I appreciate any help on this and thank you in advance. You could use File#foreach and a condition on the line, maybe a regular expression. For example: File.foreach("file.txt") do |line| next unless line =~ /^cdtr/ do_something_useful_with line end You will most probably need to tweak the regular expression to your needs. In the example I'm checking that the line starts with "cdtr", but maybe your condition is more complex, depending on the format of your file. Jesus.