cmp command returning EOF on my output despite exact match as far as i can tell cmp command returning EOF on my output despite exact match as far as i can tell unix unix

cmp command returning EOF on my output despite exact match as far as i can tell


The files you uploaded are same. It can be a line ending problem. DOS/Windows uses "\r\n" as a line ending, but Unix/Linux uses just a "\n".

The best utility on Linux machine for checking what your problem is, is "od" (octal dump) or any other command for showing files in their binary format. That is:

$ od -c uout.txt 0000000   E   n   t   e   r       t   h   e       n   u   m   b   e   r0000020   s       f   r   o   m       1       t   o       1   6       i0000040   n       a   n   y       o   r   d   e   r   ,       s   e   p0000060   a   r   a   t   e   d       b   y       s   p   a   c   e   s0000100   :  \r  \n  \r  \n       1   6           3           2       10000120   3  \r  \n           5       1   0       1   1           8  \r0000140  \n           9           6           7       1   2  \r  \n    0000160       4       1   5       1   4           1  \r  \n  \r  \n   R0000200   o   w       s   u   m   s   :       3   4       3   4       30000220   4       3   4  \r  \n   C   o   l   u   m   n       s   u   m0000240   s   :       3   4       3   4       3   4       3   4  \r  \n0000260   D   i   a   g   o   n   a   l       s   u   m   s   :       30000300   4       3   4  \r  \n  \r  \n   T   h   e       m   a   t   r0000320   i   x       i   s       a       m   a   g   i   c       s   q0000340   u   a   r   e0000344

As you can see, here the line endings are \r\n. Since you have opened and copy pasted the files, this represents your machines preferences and not the actual fiels line ending. Also you can try dos2unix utility to convert line endings.


If the files are human readable I would use diff tool instead. It has ways to ignore the line endings(see the --ignore-space-change and --strip-trailing-cr and --ignore-blank-lines).

diff -u --ignore-space-change --strip-trailing-cr --ignore-blank-lines test_cases/correct0 test_cases/uout0