Skip to main content
Note on uniq lines. One file sorted case.
Source Link
David G.
  • 3.6k
  • 1
  • 9
  • 20

If they are sorted, try:

comm -23 File1.txt File2.txt

If they aren't sorted, but it is OK to sort them, try, in bash:

comm -23 <(sort File1.txt) <(sort File2.txt)

Unless you uniq or sort -u File1.txt, lines that occur more times in File1.txt than in File2.txt will be output. This may or may not be appropriate for your use case.

If one file is already sorted, you can use a simple pipeline in most shells, like:

sort File1.txt | comm -23 - File2.txt

If they are sorted, try:

comm -23 File1.txt File2.txt

If they aren't sorted, but it is OK to sort them, try, in bash:

comm -23 <(sort File1.txt) <(sort File2.txt)

If they are sorted, try:

comm -23 File1.txt File2.txt

If they aren't sorted, but it is OK to sort them, try, in bash:

comm -23 <(sort File1.txt) <(sort File2.txt)

Unless you uniq or sort -u File1.txt, lines that occur more times in File1.txt than in File2.txt will be output. This may or may not be appropriate for your use case.

If one file is already sorted, you can use a simple pipeline in most shells, like:

sort File1.txt | comm -23 - File2.txt
Source Link
David G.
  • 3.6k
  • 1
  • 9
  • 20

If they are sorted, try:

comm -23 File1.txt File2.txt

If they aren't sorted, but it is OK to sort them, try, in bash:

comm -23 <(sort File1.txt) <(sort File2.txt)