From: Rob Biedenharn Date: 2009-08-27T01:58:58+09:00 Subject: Re: find string, get line number or position, then restart a On Aug 26, 2009, at 12:43 PM, Derek Smith wrote: > 7stud -- wrote: >> Derek Smith wrote: >>> >> >> Huh? > > Huh! > : ) > > Goal is to find pattern in file, note line number in same file, > discard > all prior lines while storing all proceeding lines after pattern was > found? OK, starting from just this, I'd say: re = /^Jul 14/ lines = [] File.open(filename) do |file| until file.eof? break if file.gets =~ re end until file.eof? lines << file.gets end end # ... do something with lines > > I have the regexp working and the store working to a table, however > getting the syntax correct for the "start at linenumber +1 from > pattern > was found" is evading me. > > 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. > -- I don't know why you'd want to seek or re-read lines given your parameters. Just the one pass is enough. Of course, if you can operate on each line inside the second inner loop, you don't even need to accumulate them into the lines array. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com +1 513-295-4739 Skype: rob.biedenharn