Created
August 26, 2015 07:30
-
-
Save Hispar/f22bd54f25cab75b0052 to your computer and use it in GitHub Desktop.
Replace domains in specified order in the given file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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