Interview Prep/Shell Scripting/Text processing: grep, sed, awk, cut, sort, uniq

How do `comm`, `diff` and `join` help compare lists?

IntermediateConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
comm -23 <(sort expected.txt) <(sort actual.txt)   # only in expected (missing)
comm -13 <(sort expected.txt) <(sort actual.txt)   # only in actual (unexpected)
diff -u old.conf new.conf                          # unified diff for humans
join -t, <(sort -t, -k1,1 users.csv) <(sort -t, -k1,1 teams.csv)   # SQL-style join on field 1

comm and join require sorted input with the same collation; use LC_ALL=C on both sides. A typical use: comparing the list of IAM users against an approved list.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Text processing: grep, sed, awk, cut, sort, uniq