If two exports contain one inventory ID per line, a textual diff can be noisy when the exporter changes its order. A set comparison answers a narrower question. Which IDs were removed, added or retained? GNU comm can answer all three after you sort both files using the same collation. Deduplicate first only when multiple copies of an ID are irrelevant.

Prerequisites and fixture

Use Bash and GNU coreutils. Save this as compare.sh and run it from a writable scratch directory. The script builds a before snapshot with a duplicate ID and then checks both the report and a deliberate sort-order failure.

set -eu
export LC_ALL=C
work=$(mktemp -d "$PWD/compare.XXXXXXXX")
trap 'rm -rf -- "$work"' EXIT
cd "$work"
printf '%s\n' copper amber copper > before
printf '%s\n' jade copper > after

sort -u before > before.sorted
sort -u after > after.sorted
removed=$(comm --check-order -23 before.sorted after.sorted)
added=$(comm --check-order -13 before.sorted after.sorted)
retained=$(comm --check-order -12 before.sorted after.sorted)

test "$removed" = amber
test "$added" = jade
test "$retained" = copper
if comm --check-order -12 before after.sorted > rejected 2>/dev/null; then
  echo 'unexpected success on unsorted input' >&2
  exit 1
fi
printf 'Removed: %s\nAdded: %s\nRetained: %s\n' "$removed" "$added" "$retained"

Run bash compare.sh. Expected output:

Removed: amber
Added: jade
Retained: copper

Read the columns by what you suppress

The three output columns represent lines only in the first input, lines only in the second input and lines common to both. The digits in -23 suppress columns two and three, so only removed IDs remain. Reversing the input files swaps added and removed. Unlike a comparison command that uses a special status for differences, a successful comm comparison can return zero whether or not there are differences. Use the output to decide whether a change occurred.

The C locale makes the comparison byte-oriented and consistent between sorting and comparing. Don't substitute numeric ordering just because IDs contain digits. comm still expects its own line collation. If you see an order error, rerun both sorts under the same locale, and do not consume partial output from the failed command. If visually identical IDs appear in both the added and removed lists, inspect them for carriage returns, trailing spaces or different Unicode encodings. Normalize only if those differences are irrelevant in your ID contract.

This script assumes nonempty IDs with no embedded newlines. Command substitution is fine for the tiny fixture but strips trailing newlines and holds the entire report in memory. For large snapshots, write each selected column to a file and use it only after the comparison succeeds. If you need to detect a change in quantities rather than membership, do not remove duplicates and adopt a report format that explicitly represents counts.

Reference: GNU Coreutils manual, section 7.4 on comm. More Linux tutorials.