Using diff/sdiff

616 Views Asked by At

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

There are 1 best solutions below

2
On

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.