0

I have one text file containing 78 numbers, and then I have another text file that contains 63 numbers that were pulled from the first file. Therefore, there are 15 numbers in text1 that doesn't exist in text2. How can I find out which ones these are?

I've tried commands such as "sdiff text1 text2", and cannot find these specific 15 numbers for the life of me. I'm sure it's simple, but I'm obviously missing it.

1 Answers1

0

Use the comm utility.

E.g., in bash:

comm -23 <(sort -n textfile1) <(sort -n textfile2)
  • comm requires sorted input, hence the process substitutions.
  • By default, comm outputs 3 columns: lines only in file 1, lines only in file2, lines in both files.
  • -23 suppresses columns 2 and 3, i.e., the command only outputs lines exclusive to file textfile1.
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • Hmm, I still get 24 values that it's showing though, as if there's 24 numbers that don't exist in text2 that's in text1. Thanks for the suggestion though. – user3528254 Apr 14 '14 at 21:43
  • @user3528254: Check the output of the sort commands individually; also make sure that neither file has extra characters beyond just numbers; check esp. the numbers you do NOT expect to see in the output. – mklement0 Apr 14 '14 at 21:46