From: Tim Hunter Date: 2008-12-20T23:30:22+09:00 Subject: Re: get first and last line from txt file - how? Mmcolli00 Mom wrote: > I have txt file with date/time stamps only. I want to grab the first > date/time and the last date/time. For instance, I will be needing > 08/09/08 3:00 and 08/24/08 3:00 from the below queued.txt. Do you know > how I can pull these out? Thanks in advance. > > queued.txt > 8/09/08 3:00 > 8/10/08 5:00 > 8/23/08 22:00 > 8/24/08 3:00 > > firstDate = "" > lastDate = "" > > File.open('queued.txt', 'r') do |f1| > while line = f1.gets > if f1.lineno == 1 then #<-this would only give me 8/09/08 3:00 > @@fistDate = f1 > end > end lines = IO.readlines("queued.txt") first = lines.first last = lines.last puts first puts last -- RMagick: http://rmagick.rubyforge.org/