Attn: sed(1) regular expression gurus

Steve Coile scoile at
Tue Jul 15 04:24:42 PDT 2003

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 (Postfix) with ESMTP id 3A4E07B03
>  by (8.11.6) ESMTP;
>  by (8.11.6p2/8.11.6) ESMTP;
>  by ([]) id 3A4E07B03
>  by ( 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
# identify valid IP address (w/o brackets)
# identify valid IP address (w/brackets)
# 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 at

More information about the freebsd-questions mailing list