Skip to content

Instantly share code, notes, and snippets.

@drewmccormack
Created January 18, 2018 10:20
Show Gist options
  • Save drewmccormack/31f217de744049eaf4e102ccc7b66ee9 to your computer and use it in GitHub Desktop.
Save drewmccormack/31f217de744049eaf4e102ccc7b66ee9 to your computer and use it in GitHub Desktop.
Common set operations to perform on email lists. Assumes one email per line, and handles case insensitivity.
# Enter two file names as arguments.
# Will print out the ones that appear in both files.
# This is a set intersection.
emails-common-to-both () {
comm -12 -i <(sort -u -f "$1") <(sort -u -f "$2");
};
# Enter two filenames.
# Will print emails from first that don't appear in second.
# This is like a set subtraction.
emails-unique-to-first () {
comm -i -23 <(sort -u -f "$1") <(sort -u -f "$2")
};
# Enter two filenames.
# Creates the union of the two (case insensitive).
emails-combined-from-both () {
sort -u -f "$1" "$2"
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment