Could someone tell me what the “line” number represents in the output of a cmp command? I ask this because, first, I can’t find it explained anywhere. Second, I am getting results comparing a set of files where the “char” outputs are identical (as expected) but the “line” outputs differ wildly.
Advertisement
Answer
The “line” outputs reflect the number of newline characters seen prior to that point in the file.
For a file which is not in a textual format, the “line” output is not likely to be meaningful, and can be ignored; for a file which is in textual format, the line number returned could be used in a text editor to navigate to the area with the difference.
For files which are not text files, line numbers simply reflect the presence of a <newline>, without any implication that the file is organized into lines.
Because by default cmp
prints only the first difference seen, the line numbers between both files are guaranteed to be identical at that point. When passed -l
, cmp
continues beyond the first difference — but no longer prints line numbers, thus avoiding any ambiguity as to which file’s line number count is canonical.