Skip to content

Instantly share code, notes, and snippets.

@Hispar
Created August 26, 2015 07:30
Show Gist options
  • Save Hispar/f22bd54f25cab75b0052 to your computer and use it in GitHub Desktop.
Save Hispar/f22bd54f25cab75b0052 to your computer and use it in GitHub Desktop.
Replace domains in specified order in the given file.
# python 3 imports
from __future__ import print_function
# imports
import fileinput
import re
# vars
domains_order = [
'www.domain1.com',
'www.domain2.com',
'www.domain3.com',
]
domains = {
'www.domain1.com',: 'replace.domain1.com',
'www.domain2.com',: 'www.replaceddomain2.com',
'www.domain3.com',: 'replace.domain3.com',
}
for line in fileinput.input(backup='.bak', inplace=True):
for key in domains_order:
# if key in domains:
line = re.sub(key, domains[key], line.rstrip())
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment