From: ni ed Date: 2012-10-08T14:44:01+09:00 Subject: How to edit a specific line in a file, without using a temp file? How to edit a specific line in a file? Writing it to a temporary file and then replace the original file works. However, I need to edit the file quite often and therefore prefer to do it using just 1 file. Tried something similar to the following, but this replaces some characters. (My intention is, if a line includes the string "my query" then modify that line to be "my query,1") File.open('mydata.csv', 'r+') do |file| file.each_line do |line| if line.include?"my query" file.seek(-line.length, IO::SEEK_CUR) file.puts ',1' break end end end Any suggestions are welcome. Thank you -- Posted via http://www.ruby-forum.com/.