From: "Pablo Q." Date: 2008-08-27T00:40:32+09:00 Subject: Re: How to open Text File and then insert line in first position? ------=_Part_5286_25422213.1219765496792 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks to both, This is what I was looking for. 2008/8/26 Craig > On Aug 26, 8:11 am, "Pablo Q." wrote: > > [Note: parts of this message were removed to make it a legal post.] > > > > Hi, > > > > I need to add a header to files, but I didn't find how open files in > append > > mode ('a') but positioned in first position. > > Does anyone know how to do that? > > > > Thanks > > > > -- > > Pablo Q. > > Try this: > > file_to_read = '/path/to/file.txt' > header = "Text to put at top of file\n\n" > file = IO.read(file_to_read) > open(file_to_read, 'w') { |f| f << header << file} > > Cheers, > > Craig > > -- Pablo Q. ------=_Part_5286_25422213.1219765496792--