Have you ever wondered what files are in one folder and not in another? Or wondered what numbers are common to two sets of numbers? Or wanted to know what words are missing from a set?

Here's a quick-and-dirty way to query two sets in bash. Using filenames as an example:

mkdir a b
touch a/{a,b,c,d}
touch b/{a,c,e,f}
find a b
{ ls a ; ls b ; ls b ; } | sort | uniq -c | sort -n

Now you can use grep to do simple set operations and remove the leading numbers with "cut -c 9-".

It's not computationally efficient, but is easier to remember than the "join" command, especially for questions like, "what's in 'a' but not in 'b'?" Answer:

{ ls a ; ls b ; ls b ; } | sort | uniq -c | sort -n | grep '^ *1' | cut -c 9-

Regards,
- Robert
http://www.cwelug.org/downloads
Help others get OpenSource software.  Distribute FLOSS
for Windows, Linux, *BSD, and MacOS X with BitTorrent

_______________________________________________
CWE-LUG mailing list
[email protected]
http://www.cwelug.org/
http://www.cwelug.org/archives/
http://www.cwelug.org/mailinglist/

Reply via email to