Last active
March 8, 2017 16:41
-
-
Save ChristopherA/38339c17981bdb664860f1c63cc6e52b to your computer and use it in GitHub Desktop.
Extract Email Shell Script
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
#!/bin/bash | |
#Works as both "./extractemail.sh filename" and "cat filename | ./myscript.sh" | |
# Set variable input_file to either $1 or /dev/stdin, in case $1 is empty | |
# Note that this assumes that you are expecting the file name to operate on on $1 | |
# # This version doesn't test if the input is a valid filename | |
# input_file="${1:-/dev/stdin}" | |
# If the script argument is provided and it is a file, then variable input_fille is | |
# assigned to the file name. If there is no valid argument then reads from stdin | |
[ $# -ge 1 -a -f "$1" ] && input_file="$1" || input_file="-" ] | |
# You can now use "$input_file" as your file to operate on | |
#grep from http://emailregex.com/ | |
grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" $input_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment