Tips & Tricks for Technologists & System Administrators | About & Contact

Set Operations Using Bash Commands


Posted 14th October in Code Samples, Linux, Shell. 2 Comments

Found a great post over at good coders code, great reuse. This one deals with performing operations on sets using only unix (bash) command line operations on files of text.

* Set Membership. Test if an element belongs to a set.
* Set Equality. Test if two sets contain the same elements.
* Set Cardinality. Return the number of elements in the set.
* Subset Test. Test if a given set is a subset of another set.
* Set Union. Find union of two sets.
* Set Intersection. Find intersection of two sets.
* Set Complement. Given two sets A and B, find all elements in A that are not in B.
* Set Symmetric Difference. Find symmetric difference of two sets.
* Power Set. Generate all subsets of a set.
* Set Cartesian Product. Find A x B.
* Disjoint Set Test. Test if two sets are disjoint.
* Empty Set Test. Test if a given set is empty.
* Minimum. Find the smallest element of a set.
* Maximum. Find the largest element of a set.

It deals with such commands as sed, awk, tr, sort, comm, grep and wc. This is a good post for anyone dealing with data via command line linux.

Full article here.


Originally posted 20081014 and last touched 20081014
Dave Drager+ is the Chief Technology Officer at XDA-Developers, where he keeps the server farm running efficiently for millions of visitors per day. He has written previously for the technology blogs Lifehacker and MakeUseOf.