From: Robert Klemme Date: 2008-11-07T02:38:44+09:00 Subject: Re: how to quickly find a string towards the end of a large io object 2008/11/6 bwv549 : > I really appreciate all the comments. They are very helpful. I > should have been more specific: > > In this case, I am dealing with a file that will usually be >= 100 > MB. It may easily be up to 1GB or more. The file is in binary form, > but about 9/10ths of the way there is a small text file embedded into > it. I need to check a parameter in the file before processing the > complete binary format (which I've decoded). At this point I only > expect to see files, but I was hoping to make it generic to any IO > object. I would settle on a solution for a file (rather than an IO > object), but I would like it to be cross-platform and prefer the > solution in ruby if it is fast enough (who wouldn't). > > Again, the basic layout of the file: > > ................................my_param = X........ > > I need the value 'X' following the 'my_para = ' For simplicity reasons I'd start with this: def get_param(file_name) size = File.size file_name File.open file_name do |io| io.seek(-(size * 0.1).to_i, IO::SEEK_END) io.read[%r{my_param\s*=\s*(\S+)}, 1] end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end