From owner-freebsd-questions@FreeBSD.ORG Mon Jul 14 11:01:52 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 CC37137B40A for ; Mon, 14 Jul 2003 11:01:51 -0700 (PDT) Received: from conn.mc.mpls.visi.com (conn.mc.mpls.visi.com [208.42.156.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0DA9A43FE1 for ; Mon, 14 Jul 2003 11:01:47 -0700 (PDT) (envelope-from hawkeyd@visi.com) Received: from sheol.localdomain (hawkeyd-fw.dsl.visi.com [208.42.101.193]) by conn.mc.mpls.visi.com (Postfix) with ESMTP id 3C5BC84AA; Mon, 14 Jul 2003 13:01:46 -0500 (CDT) Received: (from hawkeyd@localhost) by sheol.localdomain (8.11.6p2/8.11.6) id h6EI1jn29044; Mon, 14 Jul 2003 13:01:45 -0500 (CDT) (envelope-from hawkeyd) X-Spam-Policy: http://www.visi.com/~hawkeyd/index.html#mail Date: Mon, 14 Jul 2003 13:01:45 -0500 From: D J Hawkey Jr To: Rob Message-ID: <20030714180145.GA28972@sheol.localdomain> References: <20030714140816.GA27439@sheol.localdomain> <00b001c34a1b$4ad17800$a4b826cb@goo> <20030714160454.GA28042@sheol.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030714160454.GA28042@sheol.localdomain> User-Agent: Mutt/1.4.1i cc: questions at FreeBSD Subject: Re: sed(1) regular expression gurus X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: hawkeyd@visi.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jul 2003 18:01:53 -0000 On Jul 14, at 11:04 AM, D J Hawkey Jr wrote: > > On Jul 15, at 12:49 AM, Rob wrote: > > > > awk --posix -F'[^0-9A-Za-z.]+' ' > > $1 ~ /by/ { result = $2 > > for (i=3; i<=NF; i++) { > > if ($i ~ /^([0-9]+\.){3}[0-9]+$/) { > > result = result " " $i > > } > > } > > print result > > }' > > This is better than anything I've dreamed up with sed or awk, and is > really close, but it fails on this: > > by nospam.mc.mpls.visi.com (8.11.6/8.11.6.2) with ESMTP id 3A4E07B03 Another astute fellow offered this: sed -E \ -e "s/by[[:space:]]+//" \ -e "s/\(\[?(([0-9]{1,3}\.){3}[0-9]{1,3})\]?\)/\1/" \ -e "s/[[:space:]]*(\(|id|via|with|E?SMTP|;).*//" The idea being to pull anything that looks like an IP address out of parentheses first (2nd command), then junk any other parenthetical stuff with the other cruft on the line (3rd command). I did learn a new "syntax" from your script, nonetheless. Thanks, Dave -- ______________________ ______________________ \__________________ \ D. J. HAWKEY JR. / __________________/ \________________/\ hawkeyd@visi.com /\________________/ http://www.visi.com/~hawkeyd/