From: Chris Hulan Date: 2012-10-09T00:42:25+09:00 Subject: Re: How to edit a specific line in a file, without using a temp file? I think using the temp file and replacing is a good way. also lets you revert if something goes wrong. See this Stackoverflow discussion of a similar question: http://stackoverflow.com/questions/5452781/edit-each-line-in-a-file-in-ruby Reading all the info into memory, performing the work, then writing it out is another way but large files can be an issue If your worried about performance, i suggest doing some measuring to see if its really an issue and whether your planned solution is really better