-2

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.

  • 2
    *It looks like the number of carriage returns is what is being counted*. That would be exactly as expected if you read the [wc manual](https://linux.die.net/man/1/wc): "-l print the newline counts". Anyway, this is not a programming question and is thus off-topic for Stack Overwflow. – kaylum Dec 26 '20 at 03:29
  • 1
    Your file probably doesn't have a newline at the end like normal text files are expected to have. – Shawn Dec 26 '20 at 03:35
  • This question has answers here: https://stackoverflow.com/questions/12616039/wc-command-of-mac-showing-one-less-result – costaparas Dec 26 '20 at 03:53

1 Answers1

1

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.

codemonkey
  • 7,325
  • 5
  • 22
  • 36