GNU bug report logs -
#24532
GNU wc --lines doesn't report last line when that doesn't end on a new-line.
Previous Next
Reported by: Carlo Wood <carlo <at> alinoe.com>
Date: Sun, 25 Sep 2016 00:12:03 UTC
Severity: normal
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 24532 in the body.
You can then email your comments to 24532 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#24532
; Package
coreutils
.
(Sun, 25 Sep 2016 00:12:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Carlo Wood <carlo <at> alinoe.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Sun, 25 Sep 2016 00:12:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
You can argue that this is a feature, but I consider it a bug for all
practical purposes. A text file might be REQUIRED to end on a EOL
sequence (ie, '\n' for linux), in which case wc --lines works, but
consider for a moment a (otherwise) text file where the last line
does not end on a new-line:
echo "Line 1" > testfile
echo "Line 2" >> testfile
echo -n "Line 3" >> testfile
Now try to print the last two lines as follows:
$ tail -n 2 testfile
Line 2
Line 3<no new-line>
Hence, tail considers it to be a line.
Now suppose we want to print line 2 and all lines that follow,
then a reasonable attempt would be (using bash scripting):
total_lines=$(cat testfile | wc --lines)
remaining_lines=$((total_lines - 1))
tail -n $remaining_lines testfile
Right?
Counter intuitive that results in:
Line 3<no new-line>
... Line 2 wasn't printed!
Finally, sed is known to report the number of lines
as follows:
$ sed -n '$=' testfile
3
Hence, I consider it a bug that:
$ wc --lines testfile
2 testfile
Regards,
--
Carlo Wood <carlo <at> alinoe.com>
Reply sent
to
Paul Eggert <eggert <at> cs.ucla.edu>
:
You have taken responsibility.
(Sun, 25 Sep 2016 02:01:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Carlo Wood <carlo <at> alinoe.com>
:
bug acknowledged by developer.
(Sun, 25 Sep 2016 02:01:01 GMT)
Full text and
rfc822 format available.
Message #10 received at 24532-done <at> debbugs.gnu.org (full text, mbox):
Carlo Wood wrote:
> You can argue that this is a feature, but I consider it a bug for all
> practical purposes.
POSIX requires that wc -l must just count newlines, so it is indeed a feature.
If wc -l also counted incomplete lines at the end of a file, this would result
in counterintuitive behavior of a different sort. For example:
cat a b >c
wc -l a
wc -l b
wc -l c
Currently the first two numbers must sum to the third, but that would not be
true under the change you're proposing.
Incomplete lines must cause a problem of some sort, and I'm afraid that the
longstanding tradition is to cause the problem you ran into.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 23 Oct 2016 11:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 8 years and 236 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.