From owner-freebsd-questions@FreeBSD.ORG Mon Jul 14 17:55:37 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 1BEEA37B401 for ; Mon, 14 Jul 2003 17:55:37 -0700 (PDT) Received: from web14202.mail.yahoo.com (web14202.mail.yahoo.com [216.136.172.144]) by mx1.FreeBSD.org (Postfix) with SMTP id B078C43F85 for ; Mon, 14 Jul 2003 17:55:36 -0700 (PDT) (envelope-from temac@yahoo.com) Message-ID: <20030715005536.45555.qmail@web14202.mail.yahoo.com> Received: from [12.22.62.13] by web14202.mail.yahoo.com via HTTP; Mon, 14 Jul 2003 17:55:36 PDT Date: Mon, 14 Jul 2003 17:55:36 -0700 (PDT) From: Thomas McIntyre To: hawkeyd@visi.com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii cc: questions@freebsd.org cc: listone@deathbeforedecaf.net Subject: Re: 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 00:55:37 -0000 Dave wrote: > 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 I know you want to avoid perl, but this kind of problem is it's sweet spot. The following might be incrementally better (though the expression to recognize a dotted quad is technically incorrect): perl -ne ' next unless /^by/; @f=(split)[1..2]; $_=pop @f; s/^\D*//g; s/\D*$//g; push(@f,$_) if /^(\d{1,3}\.){3}(\d{1,3})$/; print join(" ", @f)."\n"; ' I'm not fluent enough to translate it but I think awk has all the required features to do so. Tom McIntyre __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com