# This file is part of ReportTool # ReportTool (Felicity) is copyright 2004-8 Steve Butterfill. # # ReportTool is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # ReportTool is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with ReportTool. If not, see . # # If you want to use ReportTool under a difference licence, email # s.butterfill@warwick.ac.uk. #!/usr/bin/python import sys search_text = sys.argv[1] replace_text = sys.argv[2] file_name = sys.argv[3] print "replacing %s with %s in %s, saving original as %s.bak" % (search_text, replace_text, file_name, file_name) in_file = open(file_name) in_text = in_file.read() in_file.close() bak_file_name = file_name+".bak" bak_file = open(bak_file_name,'w') bak_file.write(in_text) bak_file.close() out_file= open(file_name,'w') out_file.write(in_text.replace(search_text,replace_text)) out_file.close()