Comm: file is not in sorted order

commnumeric datasort

I used comm to compare two sorted files.
Each line in these files are positive integer numbers.
But the results show

comm: file 1 is not in sorted order
comm: file 2 is not in sorted order

How come the error even if these two files are sorted?

Best Answer

comm requires lexicographic sort (plain sort), not numeric sort (sort -n). For example, it wants the following order:

1
2000
300

Not the following order:

1
300
2000

Correct this and the problem should go away. For more esoteric cases where comm's locale may be different than the sort locale, you may want to run sort and comm with LC_COLLATE=C in their environment to use native byte ordering.

Related Question