From owner-freebsd-questions@FreeBSD.ORG Tue Jul 15 04:24:42 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6BAE737B401 for ; Tue, 15 Jul 2003 04:24:42 -0700 (PDT) Received: from mail.sacbee.com (filter.sacbee.com [206.107.198.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id CFCFC43FA3 for ; Tue, 15 Jul 2003 04:24:41 -0700 (PDT) (envelope-from scoile@nandomedia.com) Received: by EXCHANGEMCC with Internet Mail Service (5.5.2653.19) id <335GQ9XF>; Tue, 15 Jul 2003 04:26:53 -0700 Received: from [10.1.1.15] (10.1.1.15 [10.1.1.15]) by exchangemcc.mcclatchy.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 335GQ9XC; Tue, 15 Jul 2003 04:26:52 -0700 From: Steve Coile To: D J Hawkey Jr Date: Tue, 15 Jul 2003 06:01:52 -0400 (EDT) X-X-Sender: scoile@localhost.localdomain In-Reply-To: <20030714140816.GA27439@sheol.localdomain> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: questions at FreeBSD Subject: Re: Attn: sed(1) regular expression gurus X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jul 2003 11:24:42 -0000 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