Skip to content

Instantly share code, notes, and snippets.

@robertoostenveld
Created June 6, 2020 09:39
Show Gist options
  • Save robertoostenveld/105e70cf689078a63d2064e30b19758e to your computer and use it in GitHub Desktop.
Save robertoostenveld/105e70cf689078a63d2064e30b19758e to your computer and use it in GitHub Desktop.
replace a string in a file with another one, the string can include newlines etcetera
import sys
filename = sys.argv[1]
f=open(filename,"rb")
s=f.read()
f.close()
s=s.replace(b'OLDSTRING',b'NEWSTRING')
f = open(filename, "wb")
n = f.write(s);
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment