[olug] First Ruby on Rails user group meeting 08/20/2008 (and regex question)

Dan Linder dan at linder.org
Mon Aug 18 14:58:58 UTC 2008


On Mon, Aug 18, 2008 at 9:18 AM, Adam Haeder <adamh at aiminstitute.org> wrote:
> I'm attempting to write a shell script that will pull email addresses out
> of a file. These addresses may appear anywhere in a line. I think what I'm
> essentially looking for is a 'substring grep'. I want a grep that will
> give me part of a line that matches a regex. I've been toying with the
> idea of doing something like this:

How about this:
$ cat testfile.emails
no e-mail on this line
there's one here dan at linder.org here is one
nothing
joe@ someplace
joe at google.com
john at someplace
none
nada

$ perl -ne 'printf "%s\n", $1 if m/([\w\.]+\@[\w\.]+)/' testfile.emails
dan at linder.org
joe at google.com
john at someplace

(I'm sure someone will follow up with a perl-golf entry for a smaller
command line...Jay?)

Dan

-- 
"Quis custodiet ipsos custodes?" (Who can watch the watchmen?) -- from
the Satires of Juvenal
"I do not fear computers, I fear the lack of them." -- Isaac Asimov (Author)
** *** ***** ******* *********** *************



More information about the OLUG mailing list