From: Bob Hatch Date: 2011-02-03T00:53:46+09:00 Subject: Editing a text file and then replacing existing file I have a script that I use to find text in a file and then delete the line(s) the text is on. That part works. What I have been unsuccessfully trying to do is take the new text and overwrite the existing file that I did the search and delete on. Here is my existing code that finds the lines and deletes them: path='c:\ruby192\my_projects\IIS_Logs\ex11012607.log' search_text = %r{/memberinfo/downline/tree/can.asp} search_text2 = %r{/memberinfo/downline/tree/disto.asp} search_text3 = %r{/styles/default.css} search_text4 = %r{/scripts/generalscript.js} search_text5 = %r{/memberinfo/downline/tree/upl.asp} search_text6 = %r{/scripts/wz_jsgraphics.js} search_text7 = %r{/memberinfo/downline/tree/disfo2.asp} search_text8 = %r{/styles/png.htc} File.open(path, 'a+') do |file| file.each_line do |line| puts(line) unless line =~ search_text || puts(line) unless line =~ search_text2 || puts(line) unless line =~ search_text3 || puts(line) unless line =~ search_text4 || puts(line) unless line =~ search_text5 || puts(line) unless line =~ search_text6 || puts(line) unless line =~ search_text7 || puts(line) unless line =~ search_text8 end file.write(line) file.close end -- Posted via http://www.ruby-forum.com/.