Skip to content

Instantly share code, notes, and snippets.

@ziguane
Created January 2, 2016 21:31
Show Gist options
  • Save ziguane/9fca614558362d589863 to your computer and use it in GitHub Desktop.
Save ziguane/9fca614558362d589863 to your computer and use it in GitHub Desktop.
A perl script to extract email addresses from a text file. I use this when cleaning up bounced / undeliverable messages from the mailq. The email_to_delete.txt file is a text file that contains text + email addresses. Once the email addresses are extracted to delete_these.txt, I build an SQL query to remove them from the database.
perl -ne'if(/[\w\.\-\_]+@([\w\-\_]+\.)+[A-Za-z]{2,4}/g){print "$&\n"}' email_to_delete.txt | sort | uniq > delete_these.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment