From: luka luka Date: 2008-06-19T14:40:37+09:00 Subject: Re: Add new text to files Chris Conley wrote: > Hello, > > I'm trying to insert new text into the middle of a file with the > following: > > file = File.open("file.rb", "r+") > file.each { |line| > if line.match(/line text/) > file.puts("hello") > end > } > > This works fine except that it overwrites the existing 5 characters to > replace with "hello". Is there a way to insert a new line with new > text without overwriting any existing data? Hello Chris (: Try count lines, and when line = (what do you want, exmaple 10), continue puts into the file. -- Posted via http://www.ruby-forum.com/.