Here is the script to replace all strings in a file.
python Replace Strings In A File
#Created by Leon
import os, glob, re
old = "oldfile"
new = "newfile"
fin1 = open(old)
fout = open(newfile, "w")
data = fin1.readlines()
for line in data:
m = re.search(r"some string", line)
fout.write("some new strings")
You can also use the sed command:
1 sed -i .bk 's/OLD_STRING/NEW_STRING/g' FILE_NAME
As on some system, sed is at a very old version, and some useful characters cannot be recognized. In this case, you can use Perl as an alternative:
1 perl -e '($_ = join "",<>) =~ s/OLD_STR/NEW_STR/g; print;' OLD_FILE > NEW_FILE