help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find duplicates in a list


From: Sam Ravnborg
Subject: Re: Find duplicates in a list
Date: Sun, 27 Jul 2014 20:05:06 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Sun, Jul 27, 2014 at 11:02:57AM -0400, Jay Lawrence wrote:
> I'm sure one of the cool macro libraries has an elegant solution already,
> but here's one I just cooked up
> 
> ------------ cut here ------------------
> 
> # Given a list with duplicates
> ORIGINAL := A C B C B D A
> 
> # Build a new list in order with no dups
> $(foreach V,$(ORIGINAL),$(if $(filter $V,$(NEW)),,$(eval NEW := $(NEW) $V)))
> 
> # Or just call sort, but the order may be different
> SORTED = $(sort $(ORIGINAL))
> 
> result:
>       @echo ORIGINAL = $(ORIGINAL)
>       @echo NEW = $(NEW)
>       @echo SORTED = $(SORTED)
> 
> ------------------------------

Thanks.

In the meantime I came up with this:
------
FOO := A A B C D D E

DUPS := $(foreach v, $(FOO), $(if $(subst 1,,$(words $(filter $v, $(FOO)))),$v))

$(info DUPS=$(sort(DUPS)))
-----

This find each entry that occur more than once and prints out the entries that
occur more than once.
This matches better what I need than the proposal you came up with.
But if there is a simpler / smarter way I am all ears.

> I'm sure one of the cool macro libraries has an elegant solution already,
But then when you need this - suddenly they do not appear when you
ask google for help.

        Sam



reply via email to

[Prev in Thread] Current Thread [Next in Thread]