Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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/", line)
print(line, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment