From: Uday Thokala Date: 2007-08-24T19:42:18+09:00 Subject: How to append some data at the beginning of a file Hi, I am newbie to Ruby so please spare me if the question looks silly. My question is how to append data at the beginning of a file? Suppose I have a file named test.rb which contains some text, say "This is first line This is second line" Now if I wanted to append some data at the beginning of the file, lets say "This line has to be appended at the beginning of the file" My program filename = File.open("test","a") do |f| f.puts "This line should appear at the top of each file"; f.close(); end is appending at the end of the file. So the output is: "This is first line This is second line This line has to be appended at the beginning of the file" I searched the forums and found that if I use IO:seek and then try to append data to the existing file the earlier content which are in the first lines will get replaced. Is there any easy solution so that I can get a final output like: "This line has to be appended at the beginning of the file This is first line This is second line" -- Posted via http://www.ruby-forum.com/.