Bash, Linux

Listing all email addresses in a file with grep

The following grep command will list all email addresses from a text file and sort them per names without allowing for repetition(-u unique)

grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,7}\b" * | cut -d: -f3 | sort -u

The following grep command will list all email addresses from a text file and sort them per domain without allowing for repetition(-u unique)

grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,7}\b" * | cut -d: -f3 | rev | sort -u| rev

Leave a Reply