From owner-freebsd-questions@FreeBSD.ORG Thu Aug 28 17:34:40 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 A76A316A4BF for ; Thu, 28 Aug 2003 17:34:40 -0700 (PDT) Received: from roc-66-67-55-11.rochester.rr.com (roc-66-67-55-11.rochester.rr.com [66.67.55.11]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2213143FA3 for ; Thu, 28 Aug 2003 17:34:40 -0700 (PDT) (envelope-from vega@roc-66-67-55-11.rochester.rr.com) Received: by roc-66-67-55-11.rochester.rr.com (Postfix, from userid 1000) id EA7EA901F40; Thu, 28 Aug 2003 20:36:21 -0400 (EDT) Date: Thu, 28 Aug 2003 20:36:21 -0400 From: mpd To: Roger Williams Message-ID: <20030829003621.GA45154@rochester.rr.com> References: <20030828082600.P43491-100000@edo.naviservers.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030828082600.P43491-100000@edo.naviservers.net> User-Agent: Mutt/1.5.4i cc: questions@freebsd.org Subject: Re: Off Topic RegEx Question 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: Fri, 29 Aug 2003 00:34:40 -0000 On Thu, Aug 28, 2003 at 08:26:43AM +0900, Roger Williams wrote: > I know thins is not the place but I know one of you know this one off the > top of your head. > > I have: > > $list = "dog 1 1 1 cat 2 1 snake 111" > and I want to end up with: > dog 1 cat 2 snake 1 > I thought > $list =~ s/ \d \d/ \d/g; > would do the trick, but that gives me: > dog d 1 1 cat d snake d 1 > > Thanks, > Roger > This quick-n-dirty will do it, but ymmv on other data. There is almost definitely a better way, but this may get you started. echo "dog 1 1 1 cat 2 1 snake 111" | perl -pe 's/^(\D+ \d).* (\D+ \d).* (\D+ \d).*$/$1 $2 $3/g' apologies for the long line. -- ___________________________________________________________ "I PUT MY PANTS ON ONE LEG AT A TIME, JUST LIKE EVERYONE ELSE!" - Pokey the Penguin from "POKEY IS RELAXING (HEIRATE MICH)