SETOP(1)

🌸 NAME 🌸

setop β€” make set of strings from input. that's it, that's the girl πŸ’…


✨ DESCRIPTION ✨

okay so bestie, here's the whole vibe: setop applies set operations β€” union, intersection, set difference, all of it β€” to your input files and prints the resulting set to standard output. and by "set" we mean sorted, with unique string elements, absolutely no duplicates, we do not do repeats here πŸ’–

or, if you'd rather, it'll answer special queries for you instead β€” like how many elements are in there, because sometimes you just wanna know the count, yk?

Usage, periodt:

setop [input-stream]* [-C] [--include-empty] [--input-separator <value>] [--input-element <value>] [--trim <value>] [--combine (union|intersection|symmetric-difference|formula <value>)] [--subtract [input-stream]*] [--output (set|count|is-empty|contains <value>|equals <input-stream>|has-subset <input-stream>|has-superset <input-stream>)] [--output-separator <value>] [--quiet]

πŸ‘‘ OPTIONS πŸ‘‘

  • --help β€” spits out this help message and then dips (exits).
  • --version β€” shows the name and the version. that's it, that's the whole job πŸŽ€
  • -C, --ignore-case β€” handles input elements case-insensitively. Word and WORD? same thing to her, she's not gonna sweat it.
  • --include-empty β€” don't ignore empty elements. these lil guys can show up from empty lines, from trimming, wherever. by default she ghosts them, but with this flag she keeps them 🫢
  • -n, --input-separator arg β€” describes the form of an input separator as a regular expression in ECMAScript syntax. defaults to new line only if --input-element is not present. so like, i. e. don't forget to include the new line character \n when you set the input element manually, when desired!! fr fr, people forget that one every time 😭
  • -l, --input-element arg β€” describes the form of input elements as a regular expression in ECMAScript syntax.
  • -o, --output-separator arg (default \n) β€” the string that separates your output elements. escape sequences are allowed ✨
  • -t, --trim arg β€” trims all the given characters at the beginning and the end of elements. escape sequences allowed too πŸ’…
  • --combine arg β€” defines the combination operation applied to the given input streams. possible parameters are 'union' (that's the default, no cap), 'intersection', 'symmetric-difference', and 'formula <value>'.
  • --subtract arg β€” subtracts all elements of all the given streams from the output set. bye bye elements πŸ‘‹
  • --output arg β€” whether to output the determined set, or instead just some certain information about this set. possible parameters are:
    • set (default): streams all the output elements
    • count: just outputs the number of (different) elements, doesn't list them
    • is-empty: checks if the resulting set is empty
    • contains <element-string>: checks if the given element is contained in the set
    • equals <input-stream>: checks set equality, i. e. checks if the output corresponds with the content of <input-stream>
    • has-subset <input-stream>: checks if the content of <input-stream> is a subset of the output set
    • has-superset <input-stream>: checks if the content of <input-stream> is a superset of the output set
  • --quiet β€” suppresses all output messages in case of special queries (like, e. g., when you check if an element is contained in the set). silent queen 🀫

No input filename, or -, is equal to reading from standard input. and when an input stream shows up multiple times in the calling command, it is read only once and then cached β€” she's efficient like that, she's not doing the same work twice πŸ¦‹

The sequence of events of setop is as follows, keep up: at first, all the input files are parsed and combined according to the --combine option. after that, all the inputs from the option --subtract are parsed and removed from the result of that first step. finally, the desired output given from the option --output is printed to the screen: the set itself, or its number of elements, or a comparison to another set, etc. etc. etc. ⭐

The combination type 'formula' needs an additional string mainly consisting of positive integers and combining operators. the integers 1, 2, etc. represent the first, second, etc. input stream; the possible operators are '&' for intersection, '^' for symmetric difference, '|' for union, and '-' for set difference. at the moment, they are prioritized in that order (i. e. &, ^, |, -), but this may change in the future β€” so pls use brackets for being explicit about the order of evaluation, don't come for me later πŸ’€

Example: --combine formula '(1 | 2) & 3' unites the first and second input stream and intersects the result with the third input stream. slay.


By default each line of an input stream is considered to be an element. you can change this by defining regular expressions within the options --input-separator or --input-element. when using both, the input stream is first split according to the separator, and after that it's filtered by the desired input element form. after finding the elements they are finally trimmed according to the argument given with --trim. the option --ignore-case lets you treat Word and WORD as equal, and only the first occurrence of all input streams is considered. note that --ignore-case does not affect the regular expressions used in --input-separator and --input-element. lowkey important, highkey a gotcha πŸ™ˆ

When describing strings and characters for the output separator or for the option --trim, you can use escape sequences like \t, \n, \" and \'. but be aware that some of these sequences (especially \\ and \") might be interpreted by your shell before the string is even passed to setop. in that case you have to use \\\\ respectively \\\" just for describing a \ or a ". you can check your shell's behavior with:

echo "\\ and \""
this is the part where you go "wait why is my backslash doing that" and it's the shell, it's always the shell 😭

Special boolean queries (e. g. check if an element is contained in the set) return the exit code EXIT_SUCCESS (= 0) when the answer is 'yes', and otherwise (e. g. element not contained in set) an exit code that is guaranteed to be unequal to EXIT_SUCCESS and to EXIT_FAILURE (= 1). this way, setop can be used in the shell, bestie. main character energy fr. with the option --quiet, a verbose result message is omitted for boolean queries 🀫✨


🌈 EXAMPLES 🌈

okay these are the moment, look at her go:

setop A.txt --subtract B.txt --output contains ":fooBAR-:" --trim ":-\t" --ignore-case

case-insensitive check if the element 'foobar' is contained in A minus B. iconic. πŸ’–

setop A.txt - B.txt --combine intersection --input-element "\d+"

outputs the intersection of console, A, and B, where elements are recognized as strings of digits with at least one character; i. e. the elements are non-negative integers. math girlie behavior πŸ”₯

setop A.txt B.txt --combine symmetric-difference --input-separator [[:space:]-]

finds all elements contained in either A or B, but not both (the way she said "not both" πŸ’…), where a whitespace (i. e. \v \t \n \r \f or space) or a minus is interpreted as a separator between elements.


For bug reports, use the issue tracker at https://github.com/phisigma/setop.


aaaand that's the whole page bestie 🫢 this was setop 0.2, from April 2026 β€” go forth and union, intersect, and difference to your heart's content, and remember: <rainbow>sorted, unique, no duplicates, periodt</rainbow> πŸ‘‘πŸŒ·

πŸ“¦ where this page comes from