问题
I'm using the diff command to compare two text files. They need to be literally matched.
So I use the diff:
diff binary.out binary.expected
(By the way, those files are NOT binary files. They are text file. I call them binary because that's the name of the project)
and got
Binary files binary.out and binary.expected differ
When I use another diff tool, the smartest of all (AKA human), and there's really nothing different between the two files.
Does anyone happen to know what's going on here?
Thanks.
回答1:
Make sure to ignore white space in the diff options.
It may also see Unicode characters and interpret that as binary. See if your diff tool has an option to force text mode.
回答2:
diff
from diffutils says the following about text/binary:
diff
determines whether a file is text or binary by checking the first few bytes in the file; the exact number of bytes is system dependent, but it is typically several thousand. If every byte in that part of the file is non-null,diff
considers the file to be text; otherwise it considers the file to be binary.
hence GNU diff have a quite open definition of what is text, and the use of the --text
option to force it to treat the file as text should seldom be needed.
Have you checked if binary.out
or binary.expected
contains null characters? What version is your diff program?
来源:https://stackoverflow.com/questions/10309405/diff-command-doesnt-print-lines-that-are-different-but-still-says-the-two-file