Skip to content

Instantly share code, notes, and snippets.

@sh78
Last active June 5, 2018 21:51
Show Gist options
  • Save sh78/fd54bd00d03d5d0466ba447e65fb87e2 to your computer and use it in GitHub Desktop.
Save sh78/fd54bd00d03d5d0466ba447e65fb87e2 to your computer and use it in GitHub Desktop.
#!/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