Diff-command: doesn't print lines that are different but still says the two files are different

邮差的信 提交于 2020-01-03 09:08:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!