Categorized | linux and tip

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

This post was written by:

- who has written 19 posts on be present now.


Contact the author

One Response to “linux one liner to extract email addresses from a django log file”

  1. Alef says:

    Somebody once said:

    “Whenever faced with a problem, some people say `Lets use AWK.’ Now, they have two problems.”

    cheers,
    Alef
    ;-)

Trackbacks/Pingbacks


Twitter