From: Chris Carter Date: 2007-08-04T00:16:51+09:00 Subject: Re: Updating header in file On 8/2/07, Jeffrey Bowen wrote: > Let me try this in another way. I have a file > (test.txt) where each line contains comma separated > values and I am using CSV to work though that stored > file. The first line of the file is a header used by > the CSV program and as hash keys in the program that > creates the file. > > What I am looking to do is update test.txt in two way. > First I add a line at the end of the file with > today's values for each entry in the first line > (header). Like 1, 20, 300, etc. Which I can do with > > file = File.open("test.tet") > file.puts(x) #x being string with the comma separated > values. > > Second I will sometimes find a need to add another > header/hash key to the end of the first line. That is > replace the first line (header) with a new one. > > The only way that I can think of is to create a new > file, enter a new first line and then move line 2 > thought the last line from file 1 into file 2 and then > rename file 2 to file 1. > > I was hoping there was a way to replace the first line > in a text file. > > Thanks Jeff > > > http://rubyreports.org/. Ruport will let you parse in the file, do all sorts of data manipulation (including everything you described) and write it back out as csv. -- Chris Carter concentrationstudios.com brynmawrcs.com