Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

unix

diff

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.

like image 617
One Two Three Avatar asked Apr 25 '12 04:04

One Two Three


People also ask

When two files are identical What is the output of diff command?

When two files are identical, what is the output of diff command? Explanation: When two files are identical, diff command does not produce any output. It simply returns the shell prompt $. However, we can use the -s option to display an informative message on the terminal if the files are identical.

Which command gives all differences between two files?

Use the diff command to compare text files. It can compare single files or the contents of directories. When the diff command is run on regular files, and when it compares text files in different directories, the diff command tells which lines must be changed in the files so that they match.

How do you check if two files are exactly the same?

Probably the easiest way to compare two files is to use the diff command. The output will show you the differences between the two files. The < and > signs indicate whether the extra lines are in the first (<) or second (>) file provided as arguments.

What does the command diff do in Unix with respect to files?

diff stands for difference. This command is used to display the differences in the files by comparing the files line by line.


1 Answers

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?

like image 147
hlovdal Avatar answered Sep 30 '22 15:09

hlovdal