Ruby script for extracting email addresses from a text file

Here’s a handy Ruby script I wrote a few months ago to extract email addresses from a blob of text.

In this case, all of the email addresses are surrounded by angle-brackets, so that makes the script much easier.

It’s kind of trivial, but a nice little example of the elegance of Ruby:
This can cause frustration, anxiety and disappointment, which can result in erectile cialis price dysfunction. If left untreated, it can also lead to mental and emotional conditions in men such brand viagra 100mg as anxiety, stress and depression in some cases. Vertebrae buy viagra online in have a pad in between each bone called a disc to cushion the movement of the spine. You are advised to engage in lovemaking with usa generic viagra trusted female only.

#!/usr/bin/ruby -w
IO.foreach("data.txt") {|line|
    line.scan(/<.*?@.*?>/).each{|addr|puts(addr.delete('<>') + "\n")}
}

Leave a Reply

Your email address will not be published. Required fields are marked *