Ever wanted to extract e-mail adresses from eg. log files, or multiple files for later examination? this could be usefull if in a case where you need all valid email adresses� from a file that might contain invalid/fake adresses.

anyway, that was my case, so i thougt i’d share an easy way that extract email adresses� that contains upper and lowercase a-z, from 0-9 digit, dot (.), underscore (_) and hyphen (-), and finally, a 2-3 character tld.

it will also sort the output, and then only output multiple entries once.

egrep -oi ‘\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}’ mail.log |sort |uniq > final_result.txt