10 months ago by
Baylor College of Medicine, Houston, TX
wc -l
counts the number of new lines, not the number of lines. If your file ends with the last character of the last line, it will amount to one fewer line than the other file but diff would ignore differences. Try running a diff
.
echo "Hello World" | wc
1 2 12
As you can see, the above has ` line and 12 characters, whereas the one below where the new line is suppressed has 0 lines and 11 characters.
echo -n "Hello World" | wc
0 2 11
•
link
modified 10 months ago
•
written
10 months ago by
Ram ♦ 32k
Hello again. You could check the output of
head
andtail
on both files, and that should reveal the discrepancy.Kevin
I did all lines match in both files
You could try the
diff
command. The discrepancy is likely related to encoding and end-line characters, e.g., Windows carriage returns (\r
) versus end-line characters on Linux (\n
)head
/tail
would have freaked out on one of the files if the line endings had been different between them.The initial assumption with
head
andtail
was that there may have been a blank line at the beginning or end of one of the files. We cannot see the user's actions from where we are sitting.