Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
Last active June 23, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbarbarosh/7794d4a48d207b463e1145e788604402 to your computer and use it in GitHub Desktop.
Save vbarbarosh/7794d4a48d207b463e1145e788604402 to your computer and use it in GitHub Desktop.
shell_lines_common – Show common lines in two files https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Show common lines in two files
# https://unix.stackexchange.com/a/398143/121657
# > Use comm -12 file1 file2 to get common lines in both files.
# >
# > You may also needs your file to be sorted to comm to work as
# > expected.
# >
# > comm -12 <(sort file1) <(sort file2)
# >
# > From man comm:
# >
# > -1 suppress column 1 (lines unique to FILE1)
# > -2 suppress column 2 (lines unique to FILE2)
comm -12 <(sort emails-prod.txt) <(sort emails-dev.txt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment