On Sep 7, 3:03 am, Bulhac Mihai <mihai.bul... / yahoo.com> wrote:
> how can i read only a line from a txt file?
> for example i want to read only line 3
> --
> Posted viahttp://www.ruby-forum.com/.

ruby -e "puts ARGF.to_a[2]" myfile

Another way:

File.open("myfile"){|f|
  line = nil
  3.times { line = f.gets }
  puts line
}

If the whole file will fit in memory,
you can do this:

puts IO.readlines("myfile")[2]