I don't know how strict your sed
tag is, but a universal way to replace string(s) in a file by the command:
<script> <file> <old_string> <new_string>
you could use the tiny python script below:
#!/usr/bin/env python3
import sys
file = sys.argv[1]; old_string = sys.argv[2]; new_string = sys.argv[3]
with open(file) as src:
lines = src.read()
print(lines.replace(old_string, new_string))
Copy the script into an empty file, save it as replace.py
make it executable (to run it without python3
prefix), run it by the command:
/path/to/replace.py /path/to/file dev.example.com example.com
In case either old_string or new_string has spaces, use quotes:
/path/to/replace.py /path/to/file 'old string with spaces' 'new string with spaces'
g
:sed 's/text1/text2/g' file-name
.