Bil Kleb wrote:
> So, the tasks are roughly,
>
> 1) Goto line 1707 of the file
> 2) Search backward until line.match /WdtW/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.
Vidar
|