Search code examples
linuxwc

Using the line count command wc -l <document_name> (Linux), I am getting a return of the number of lines minus 1


It looks like the number of carriage returns is what is being counted. Also, the command line is concatenated with the last line of text when I do the cat command. So,

cat newdoc

gives me the last line

be savedorangepi@OrangePi:~

where 'be saved' is the last line of the document with the cmd line continuing on the same line and

wc -l newdoc

returns

9 newdoc

orangepi@OrangePi:~

for a 10 line document without the cmd line continuing on the same line.


Solution

  • Be careful with wc as it will NOT count the very last line unless it has the EOL character at the end. Use grep -c "" filename instead.