Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active February 19, 2017 13:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nepsilon/4abe1d3325eaee4264e3c61463d4e859 to your computer and use it in GitHub Desktop.
Save nepsilon/4abe1d3325eaee4264e3c61463d4e859 to your computer and use it in GitHub Desktop.
CLI: Output the difference between 2 files — First published on fullweb.io issue #43

CLI: Output the difference between 2 files

Thinking of using diff? Try comm, its sole purpose is to compare 2 sorted files line by line.

Show lines in A.txt but NOT in B.txt:

comm -2 -3 A.txt B.txt

If the files aren’t sorted, use:

comm -2 -3 <(sort A.txt) <(sort B.txt) 

Show lines in B.txt but NOT in A.txt:

comm -2 -3 B.txt A.txt 

BONUS: Show lines in both files (UNION):

comm -1 A.txt B.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment