Insert into textfile

I have a text file that I want to insert a new line into between the
first and second line. Is there a way to do this?

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

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.