15

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?

1
  • 1
    In my case I had sorted (lexicographic ascending) the files using notepad++, which considers small case letters, and capital case letters separate eg. a will appear after 'Z' in ascending sort. This is different from how sort utility (bash) sorts. To verify this I converted all lines to upper case, and then sorted in np++, comm no longer complained. Sep 6, 2019 at 12:12

1 Answer 1

20

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.