Last active
February 6, 2018 13:13
-
-
Save Siddhartha90/6096514 to your computer and use it in GitHub Desktop.
A python script which anonymizes email addresses in all files in current directory and sub-directories.
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
# A python script which anonymizes email addresses in all files in current directory and sub-directories. | |
# e.g. A file with the following contents: | |
# [email protected] | |
# Sid Phn#- 6385833322 | |
# [email protected] | |
# [email protected] | |
# [email protected] | |
# Would change to: | |
# [email protected] | |
# Sid Phn#- 6385833322 | |
# [email protected] | |
# [email protected] | |
# [email protected] | |
import os | |
import re | |
from os.path import join, getsize, isfile | |
def main(): | |
for root, dirs, files in os.walk('.'): | |
for filename in files: | |
if not filename.startswith('.'): | |
filename = join(root, filename) | |
myfile = open(filename, 'r') | |
content = myfile.read() | |
content = re.sub(r'.+(?=@.+\.(.+))', "xxxx", content) | |
myfile = open(filename, 'w') | |
myfile.write(content) | |
myfile.close() | |
# Call the main function. | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment