Skip to content

Instantly share code, notes, and snippets.

@kojiwell
Last active December 16, 2015 19:39
Show Gist options
  • Save kojiwell/5487114 to your computer and use it in GitHub Desktop.
Save kojiwell/5487114 to your computer and use it in GitHub Desktop.
sed -i -e 's/old_word/new_word/' /path/to/filename.conf in python
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
#
# sed_file.py is;
#
# sed -i -e 's/old_word/new_word/' /path/to/filename.conf
#
import fileinput, sys
for line in fileinput.input('/path/to/filename.conf', inplace=True):
line = line.replace('old_word', 'new_word')
# sys.stdout is redirected to the file
sys.stdout.write(line)
# refered links: http://stackoverflow.com/questions/1582750/edit-text-file-using-python,
# http://docs.python.org/2/library/fileinput.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment