Date: Tue, 15 Jul 2003 06:01:52 -0400 (EDT) From: Steve Coile <scoile@nandomedia.com> To: D J Hawkey Jr <hawkeyd@visi.com> Cc: questions at FreeBSD <freebsd-questions@freebsd.org> Subject: Re: Attn: sed(1) regular expression gurus Message-ID: <Pine.LNX.4.44.0307150542570.26376-100000@localhost.localdomain> In-Reply-To: <20030714140816.GA27439@sheol.localdomain>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 14 Jul 2003, D J Hawkey Jr wrote: >I'm getting really frustrated by a seemingly simple problem. I'm doing >this under FreeBSD 4.5. > >Given these portions of an e-mail's multi-line Received header as tests: > > by some.host.at.a.com (Postfix) with ESMTP id 3A4E07B03 > by some.host.at.a.com (8.11.6) ESMTP; > by some.host.at.a.different.com (8.11.6p2/8.11.6) ESMTP; > by some.host.at.another.com ([123.4.56.789]) id 3A4E07B03 > by some.host.at.yet.another.com (123.4.56.789) id 3A4E07B03 # tested with sed-4.0.5-1 for RHL 9.0 # remove junk we don't care about s/^.*by \([^ ]*\) (\([^)]*\)).*$/\1 \2/ # identify valid hostname s/^[[:alnum:]][-[:alnum:]]*\(\.[[:alnum:]][-[:alnum:]]*\)*/host:&/ # identify valid IP address (w/o brackets) s/[[:digit:]]\{1,3\}\(\.[[:digit:]]\{1,3\}*\)\{3\}$/ipaddr:&/ # identify valid IP address (w/brackets) s/\[\([[:digit:]]\{1,3\}\(\.[[:digit:]]\{1,3\}*\)\{3\}\)\]$/ipaddr:\1/ # discard if no valid hostname or IP address /\(^host:\| ipaddr:\)/!d # if valid IP address, discard anything else s/^.* ipaddr:// # if valid hostname, discard anything else s/^host:\([^ ]*\).*$/\1/ -- Steve Coile Systems Administrator Nando Media ph: 919-861-1200 fax: 919-861-1300 e-mail: sysadmins@nandomedia.com http://www.nandomedia.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.44.0307150542570.26376-100000>