setdiff is a small command line utility to compare two line-oriented files using set operations.
- Set difference (
A \ BorB \ A) - Set intersection
- Set union
- Symmetric difference with line prefixes
- Unique lines (symmetric difference)
Build from source using Cargo:
cargo build --releaseThe compiled binary will be located at target/release/setdiff.
setdiff [OPTIONS] <FILE1> <FILE2>
Exactly one mode option must be provided:
--only-first– show lines only inFILE1(A \ B).--only-second– show lines only inFILE2(B \ A).--common– show the intersection of both files.--union– show the union of both files.--diff– display a symmetric difference with lines fromFILE1prefixed by<and lines fromFILE2prefixed by>.--unique– list lines that appear in exactly one of the files.
Lines are sorted and deduplicated before the operation is performed.
$ cat a.txt
apple
orange
banana
$ cat b.txt
banana
kiwi
orange
$ setdiff --only-first a.txt b.txt
apple
$ setdiff --unique a.txt b.txt
apple
kiwiRun the test suite with:
cargo testThis project is released under the MIT license.