[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wc -l doesn't count partial lines

From: Bob Proulx
Subject: Re: wc -l doesn't count partial lines
Date: Sun, 25 Jan 2009 10:36:16 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

address@hidden wrote:
> If a file has no newline at the end of the last line, the last line  
> doesn't get counted.

Thanks for the report.  However that is the way it is supposed to
work.  The 'wc -l' command counts the number of newline characters in
the file.  It can't count missing newlines as being there.  If it did
that would break other applications that rely upon an accurate count.
This is the way 'wc' has always behaved for 30 years and counting.

The standards document how wc should behave here:


  Write to the standard output the number of <newline> characters in
  each input file.

> But as an edge case, this one is actually slightly less likely to make  
> people mad!  I could almost see an argument for "0" being the right  
> answer here; nevertheless, the first example seems clearly wrong to me.

The problem really comes down to why you would have a "text" file that
didn't end with a newline.  Is that a text file or is that a binary
file?  Shouldn't all text files end with a newline character because
newlines terminate text file lines?  Not ending in a newline tells me
that this is not a text file.  And if it is not a text file then
obviously wc can't modify the count of newline characters in the
file.  In the end 'wc' can only count what is there exactly and can't
make interpretations of it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]