Skip to content

Instantly share code, notes, and snippets.

@lanbugs
Created June 22, 2018 22:45
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/ee428978bf94eb92a97ca3fefddd3825 to your computer and use it in GitHub Desktop.
Save lanbugs/ee428978bf94eb92a97ca3fefddd3825 to your computer and use it in GitHub Desktop.
Search and replace in files with python3
#!/usr/bin/env python3
import fileinput
import re
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)
print(line, end='')
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment