Pattern matching with awk

Peter Mielke peter at doe.utoronto.ca
Thu Mar 7 11:39:04 AEST 1991


In <1994 at tssi.UUCP>, tssi!nolan writes:
> lin at CS.WMICH.EDU (Lite Lin) writes:
> >  This is a simple question, but I don't see it in "Freqently Asked
> >Questions", so...
> >  I'm trying to identify all the email addresses in email messages, i.e.,
> >patterns with the format user at node.  Now I can use grep/sed/awk to find
> >those lines containing user at node, but I can't figure out from the manual
> >how or whether I can have access to the matching pattern (it can be
> >anywhere in the line, and it doesn't have to be surrounded by spaces,
> >i.e., it's not necessarily a separate "field" in awk).
> 
> [stuff about awk or gawk]
> 
> Then that gives a pattern something like this
> 
> [a-zA-Z0-9.\-_%!]+@[a-zA-Z0-9.\-_]+
> 
> I've escaped the dash, I suppose it might be necessary to escape other
> characters as well.  Have I left anything out that might occur in strange
> but otherwise valid mail addresses?

Or you could use sed to transform the address when it matches. eg.

sed -e 's/\([a-zA-Z0-9.\-_%!]*\)@\([a-zA-Z0-9.\-_]*\)/machine: \2 userid: \1/'

-- 
Peter Mielke                                    peter at doe.utoronto.ca
Dictionary of Old English Project               utgpu!utzoo!utdoe!peter
University of Toronto



More information about the Comp.unix.questions mailing list