[YLUG] Subtracting one list from another.

Richard G. Clegg richard at richardclegg.org
Sun Mar 25 15:42:03 BST 2007


Pete Jackson wrote:
> 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.

cat g1.txt | sort | uniq | cat g2.txt g2.txt - | sort | uniq -u

will print one copy of any line which appears only in g1.txt.
Note that it might stumble over whitespace -- the line a with a
space following is different from the same line without.

-- 
Richard G. Clegg,
Dept of Elec. Eng.,
University College London
http://www.richardclegg.org/



More information about the York mailing list