LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] [TOTD] set operations on the command line

[ILUG] [TOTD] set operations on the command line

Pádraig Brady P at draigBrady.com
Thu Jun 8 12:11:19 IST 2006


Following on from my previous mail
about finding cruft on a debian system with:
(cat /var/lib/dpkg/info*.list ; find / -type f ) | LANG=C sort | uniq -u

I find set operations like that quite common on the command line:

For unsorted files:

LANG=C sort file1 file2 | uniq              #Union
LANG=C sort file1 file2 | uniq -d           #Intersection
LANG=C sort file1 file1 file2 | uniq -u     #Difference
LANG=C sort file1 file2 | uniq -u           #Symmetric Difference

For sorted files:

LANG=C comm file1 file2 | sed 's/^\t*//'    #Union
LANG=C comm -12 file1 file2                 #Intersection
LANG=C comm -13 file1 file2                 #Difference
LANG=C comm -3 file1 file2 | sed 's/^\t*//' #Symmetric Difference

Note the LANG=C for speed as we're not interested
in the actual order of the items.

Pádraig.



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell