Last active
June 5, 2018 21:51
-
-
Save sh78/fd54bd00d03d5d0466ba447e65fb87e2 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import fileinput | |
import re | |
## | |
# Extract email addresses from file or `stdin` | |
# | |
# Prints out a standard list of email address substrings contained in `fileinput` | |
# Call on a file or pipe to `stdin` | |
# | |
# extract-email.py messy_file.txt | |
# ./some-script --messy | extract-email.py | sort | unique > emails.txt | |
## | |
regex = re.compile(r"\S*\@\S*") | |
string = "" | |
for line in fileinput.input(): | |
string += line | |
matches = re.findall(regex, string) # => array | |
print("\n".join(matches)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment