From: Rong Date: 2008-09-15T05:32:16+09:00 Subject: Re: insert into textfile Actually, that was close. This is what I was kind of looking for. content = File.read('exam.txt') content.sub!("\n","\nNew Content\n") File.open('exam.txt','r+').write(content) But this doesn't work if the first line doesn't end in a new line character. On Sep 14, 7:33 am, thomas peklak wrote: > content = File.read('test.txt') > content.sub!("\n","\n\n") > File.open('test.txt','w').write(content) > > sub does replace the first occurence of a new line in the file > > thomas