Off Topic RegEx Question

mpd mpd at rochester.rr.com
Thu Aug 28 17:34:40 PDT 2003


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)


More information about the freebsd-questions mailing list