Page 1 of 1

"wc - l foo.csv" returns 1 less than total number of lines

Posted: Thu Jan 17, 2008 1:06 pm
by Luke
I am not really a linux expert by any means, but shouldn't this command return the number of lines in "foo.csv"?

Code: Select all

wc -l foo.csv
When I execute this, if the file is 4 lines long, it returns 3, if the file is 200 lines long, it returns 199. What is the deal?? :(

Re: "wc - l foo.csv" returns 1 less than total number of lines

Posted: Thu Jan 17, 2008 3:38 pm
by VladSun
It counts the number of new lines - so, if you have no new line char after the last char at the last line of your file it will ignore it.

Re: "wc - l foo.csv" returns 1 less than total number of lines

Posted: Sat Jan 19, 2008 12:17 am
by Luke
Oh, well that makes perfect sense. :) Guess I will just have to make sure the file ends in a newline then.

Re: "wc - l foo.csv" returns 1 less than total number of lines

Posted: Thu Jan 24, 2008 10:19 pm
by Chris Corbyn
The Ninja Space Goat wrote:Oh, well that makes perfect sense. :) Guess I will just have to make sure the file ends in a newline then.
This is almost always good practise. But in any case would be easy to check :)