From: "Peña, Botp" Date: 2007-08-25T10:12:20+09:00 Subject: Re: How to append some data at the beginning of a file On Behalf Of Uday Thokala: # newfile = File.new("test1","w") # newfile.puts "This line should appear at the top of each file"; # oldfile = File.open("test", "r+") # oldfile.each_line { |line| newfile.puts line} # oldfile.close(); # newfile.close(); # File.delete("test"); # File.rename("test1", "test"); that is nice, but it would be ideal if your code is immune to dependencies (like static filenames, fixed number of files, etc) eg, consider the *nix cat command, you can easily insert lines at the beginning or end. In your case eg, irb(main):006:0> system "ls -la test2.txt" ls: test2.txt: No such file or directory => false irb(main):007:0> system "cat test.txt" 1 2 3 this is a test=> true irb(main):008:0> text_insert="this will be inserted" => "this will be inserted" irb(main):009:0> system "echo #{text_insert} | cat - test.txt" this will be inserted 1 2 3 this is a test=> true irb(main):010:0> new_file="test2.txt" => "test2.txt" irb(main):011:0> system "echo #{text_insert} | cat - test.txt > #{new_file}" => true irb(main):012:0> system "ls -la test2.txt" -rw-r--r-- 1 root root 42 Aug 25 09:02 test2.txt => true irb(main):013:0> system "cat test2.txt" this will be inserted 1 2 3 this is a test=> true irb(main):014:0> note that cat is simply flexible. eg, cat f - g will concatenate file f, standard input, and file g in that order; thus inserting standard input bw the contents of files f and g. i think ARGF is flexible enough. just a simple thought. kind regards -botp