[YLUG] Subtracting one list from another.

Richard Birnie rbirnie at totalise.co.uk
Sun Mar 25 14:08:53 BST 2007


Hi,

If you know any Perl at all then there's a module on CPAN that is designed for 
exactly this task. Take a look at this 
http://search.cpan.org/~jkeenan/List-Compare-0.33/lib/List/Compare/Functional.pm
The get_unique or get_complement functions are probably what you want.

I'm sure there'll be a lot of people going 'yuck, perl' at this point. To 
those people I say: meh. :-)

Rich

On Sunday 25 March 2007 13:48:44 Gaffer wrote:
> Thankyou Pete,
>
> On Sunday 25 March 2007 13:05, Pete Jackson inscribed thus:
> > Hi,
> >
> > I think something like "cat g1.txt g2.txt | sort | uniq -u" will
> > give you all items that appear in exactly one of the lists (the
> > '-u' flag means print only unique lines).  You'd need to make sure
> > each item appeared at most once in each source list for this to
> > work.
> >
> > Hope that helps, and I've not misunderstood the problem,
> >
> > Pete
>
> I tried something similar to this but end up with a file that contains
> everything in both files but not the files that occur in one but not
> the other.  Since these are both text files "file one + file two |
> sort -u"  gives me the same result !
>
> Where I am trying to get to, is a file that only contains the
> difference.   Which is what I thought "diff" was supposed to do !
>
> > Gaffer wrote:
> > > Hi Guys,
> > >
> > > How can I subtract items from two lists where one list has items
> > > that are not in the other list in order to get a list of those
> > > items ?
> > >
> > > Sorry if that sounds confusing !
> > >
> > > I have tried   "diff -a g1.txt g2.txt > g3.txt"  but I end up
> > > with a file that is as big as the sum of the g1 + g2 file sizes
> > > and seems to have as entries that are not in either file.
> > >
> > > cmp just says the first line is different and stops.
> > >
> > > I'm obviously doing something wrong..........!!
> >
> > _______________________________________________
> > York mailing list
> > York at lists.lug.org.uk
> > https://mailman.lug.org.uk/mailman/listinfo/york



More information about the York mailing list