From: Robert Klemme Date: 2012-08-24T17:38:00+09:00 Subject: Re: Add a line into a file at multiple locations above a existing line On Fri, Aug 24, 2012 at 10:22 AM, Aravind K. wrote: > Hi All, > > I am working a ruby code to append lines to a existing file at some > specified location. I do that by finding a particular string and append > the line below that. In a certain case i am trying to add a particular > line say welcome before a existing line, > > Eg. line1 > line 2 > line3 > ) > > line4 > > I will need to add the line above line 4 as i cant append it after ) as > there may be several )'s. What is the way that i can do this? > > It would be of great help. Thanks in advance. Just iterate the file line by line and output the new line before you output the matching line. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/