Do shells such as bash and ksh support set operations (such as 'union of two sets')? I can't find any tutorial about this using Google.
问题:
回答1:
What about this set-operations-in-unix-shell.
回答2:
As far as I know, POSIX shell (including bash) doesn't support sets operation. But you can build your own, for example, by making use of bash associative array (bash 4.0 and later).
回答3:
No bash/ksh doesn't support dedicated sets operations. You will have to program your own if you insists on using the shells..like what the link xdazz provided has done. If you want full dedicated set operations (also in terms of performance), use a real programming language (eg Python, Ruby etc )
回答4:
I wrote a program recently called Setdown that does Set operations from the cli.
It can perform set operations by writing a definition similar to what you would write in a Makefile:
someUnion: "file-1.txt" \/ "file-2.txt"
someIntersection: "file-1.txt" /\ "file-2.txt"
someDifference: someUnion - someIntersection
Its pretty cool and you should check it out. I personally don't recommend the "set operations in unix shell" post. It won't work well when you really need to do many set operations or if you have any set operations that depend on eachother.
At any rate, I think that it's pretty cool and you should totally check it out.