Linux one liner to extract email addresses from a Django log file
Say something bad happened and your application sent emails that it shouldn’t have (ahem who? not me…) and you want to collect the emails to apologise.
So you just copied the output of a log file in a text file (wrong.txt) like the following:
sending message 'Confirm email address for example.com' to email1@test1.com
sending message 'Confirm email address for example.com' to email2@test2.com
[...]
sending message 'Confirm email address for example.com' to email3@test3.com`
Unix command line tools can make the job of extracting those emails and make them ready to be used in a To (or BCC) field a one liner:
cat wrong.txt | awk {'print $9'} | uniq | xargs -I{} echo -n "{},"
The result is:
email1@test1.com, email2@test2.com, [...], email3@test3.com
12 November 2008