Skip to content

Instantly share code, notes, and snippets.

@lanbugs
Created June 22, 2018 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lanbugs/1c872daaa9e5ce3b12b9e2f12ea44da8 to your computer and use it in GitHub Desktop.
Save lanbugs/1c872daaa9e5ce3b12b9e2f12ea44da8 to your computer and use it in GitHub Desktop.
Search and replace in file with python 2.x
#!/usr/bin/env python
import fileinput
import re
import sys
file = fileinput.FileInput("/etc/ssh/sshd_config", inplace=True, backup=".bak")
for line in file:
line = re.sub(r".*Banner.*","Banner /etc/issue.net", line)
sys.stdout.write(line)
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment