From: Dylan Date: 2009-08-27T01:40:20+09:00 Subject: Re: find string, get line number or position, then restart at +1 On Aug 26, 8:44 am, Derek Smith wrote: > Hi All, > > First off I want to say this list is very helpful and people are nice > and polite compared to many other email lists and forums I have been on > for years and years, notably the camel lists. Thank you! > > Ok so I have a file where I am searching for the string "Jul 14.*" for > example using a regexp and this is working fine.  However I have been > debating on how to move forward with what code, $. or tell with seek? > > for each line in file >    linenumber = $. if /^string/ > end > > for each line in file >    linenumber = tell line if /^string/ > end > > Will either of the above pseudo-code work? > > seek to linenumber and add 1 > start re-reading at linenumber+1 and store data until EOF. > > Please help and or provide sample code? > > thank you > -- > Posted viahttp://www.ruby-forum.com/. I'm not sure I'm understanding your question right, but it sounds like you want all the data in a file after "Jul 14"? If so there's no need to traverse through and then seek. Try something like this: regex = /^Jul 14/ found = false data = Array.new() file = File.open("file","r") file.each{|line| data << line if(found) found = true if(line =~ regex) } puts data.join("\n") This will put everything after the line starting with "Jul 14" into an array delineated by lines. Then you can do whatever you want with it. If you wanted to alter it so it grabs the data between two different regexes just add another if(line =~ regex2) line and change found to false. Hope this helps! -Dylan