Hi, Does anyone know if it is possible to read say the last 10 line of a file? readlines would work if memory is unlimited, but that isn''t the case, especially if the file is a 2GB log file. Or is this not possible at all? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Does anyone know if it is possible to read say the last 10 line of a > file? readlines would work if memory is unlimited, but that isn''t the > case, especially if the file is a 2GB log file. Or is this not possible > at all?Never used it, but a google search for ''ruby file tail'' turns up this: http://raa.ruby-lang.org/project/file-tail/ You could also get the size of the file, open it, and then seek to somewhere near the end and just start reading at that point till you reach the end... -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 16, 2007, at 11:57 AM, Philip Hallstrom wrote:>> Does anyone know if it is possible to read say the last 10 line of a >> file? readlines would work if memory is unlimited, but that isn''t >> the >> case, especially if the file is a 2GB log file. Or is this not >> possible >> at all? > > Never used it, but a google search for ''ruby file tail'' turns up this: > > http://raa.ruby-lang.org/project/file-tail/ > > You could also get the size of the file, open it, and then seek to > somewhere near the end and just start reading at that point till > you reach > the end... > > -philipI *have* used file-tail and taken a look at the code. It seems to be well written and covers possible gotchas quite well. For example, to get the revision number out of the revisions.log file that capistrano adds a line to on each deploy: rev = File.open(name) do |f| f.extend(File::Tail) f.rewind(1).gets.match(/(\d+) \d{14}$/)[1] end You gotta like that! -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot. file-tail is exactly what I am looking for. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---