unless line && filename then print"Invalid parameter.\n" print"Usage:ruby tail.rb line filename\n" end
line = line.to_i
begin io = open(filename) n = 0 lc = 0 stack = Array.new
whilelc < line + 1do n = n + 1 io.seek( -n, IO::SEEK_END ) ifio.pos == 0then break end #break unless io.seek( -n ,IO::SEEK_END) s = io.read( 1 ) if/\n/ =~ s then lc = lc + 1 end end
io.seek(-n, IO::SEEK_END) s = io.read() last = io.pos prints
while item = io.read() do if ! item.empty? then print item last = io.pos else io.pos = last end end