Skip to content

Instantly share code, notes, and snippets.

@Arsh25
Created February 28, 2017 19:18
Show Gist options
  • Save Arsh25/3d7328bb3f2f908a04db06174767318f to your computer and use it in GitHub Desktop.
Save Arsh25/3d7328bb3f2f908a04db06174767318f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
# Arsh Chauhan
# 02/28/17
# Last Edited:02/28/17
# replace.py: replace domains of emails with a domain you want
import re
# in_file: File with orginal emails
# out_file: Output file with original email domain replaced with domain
# domain: The domain you want
def replace_domain(in_file,out_file,domain):
new_emails = []
tld = domain[domain.find('.')+1:]
with open (in_file,'r') as emails:
for email in emails:
new_email = re.sub('@.',domain,email)
new_email = new_email[:new_email.find(tld)+len(tld)]
new_emails.append(new_email+'\n')
with open (out_file,'w') as replaced_emails:
for email in new_emails:
replaced_emails.write(email)
if __name__ == "__main__":
replace_domain('old_emails','correct_emails','catpowered.local')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment