On Oct 11, 2006, at 7:35 AM, Vidar Hokstad wrote: > > Bil Kleb wrote: >> So, the tasks are roughly, >> >> 1) Goto line 1707 of the file >> 2) Search backward until line.match /\Wdt\W/i >> 3) Remove /dt/i >> >> I'm stuck on an elegant, i.e., Ruby, way to do the first >> two steps. Please point me toward the glittering light. > > For 1) Assuming the lines aren't fixed length: Read in the entire file > into an array (using IO#readlines), in which case you can skip > straight > to the line you want, or counting line by line until you find the one > you want. > > For 2) Any particular reason why you need to search backwards? My > suggestion would be to look at String#gsub - that will help you handle > both 2) and 3) in one go. I like this idea, but I would suggest using a hash rather than an array. Hash the lines keyed to their line number. Then you can search any which way you like. Regards, Morton