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.
More on Text processing: grep, sed, awk, cut, sort, uniq
What are the most useful `grep` flags?BeginnerWhat is the difference between basic, extended and Perl regular expressions in grep?IntermediateWhat are the core `sed` commands you use in automation?BeginnerWhy does `sed -i` behave differently on macOS and Linux?IntermediateHow do you use variables inside a `sed` expression safely?AdvancedWhat is the structure of an `awk` program?Beginner