[Gllug] strip invalid email addresses

- Tethys tethys at gmail.com
Fri Dec 7 17:59:03 UTC 2007


On Dec 7, 2007 5:21 PM, countd <countd42 at googlemail.com> wrote:

> I have a plain text list of email addresses. Can anyone help me with a
> one liner (sed?) to strip out the invalid ones? I can see for example
> that there are telephone numbers in there, and lines with no @ sign
> which I'd like to get rid of.

This is actually harder than you'd expect (although not as hard as
some misinformed pages on the net would have you believe). This is a
simple regexp that will catch 99% of valid Internet email addresses.
It's fine for filtering out valid addresses from a list like this
(accepting that it'll miss a few valid ones), but don't even think
about using it to validate an address in real time on a wbe form or
similar, for example.

sed -rn '/^.*@[-A-Za-z0-9]+\.[-A-Za-z0-9.]+$/p' addr.txt

Tet

-- 
Perl is like vise grips. You can do anything with it but it is the
wrong tool for every job. -- Bruce Eckel
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list