GNU bug report logs -
#23190
wc - Different output
Previous Next
Reported by: Seva Adari <oddissyus <at> gmail.com>
Date: Sat, 2 Apr 2016 19:26:02 UTC
Severity: normal
Tags: notabug
Done: Assaf Gordon <assafgordon <at> gmail.com>
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 23190 in the body.
You can then email your comments to 23190 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#23190
; Package
coreutils
.
(Sat, 02 Apr 2016 19:26:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Seva Adari <oddissyus <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Sat, 02 Apr 2016 19:26:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hello,
I am not sure if this a bug or expected behavior! Here is different output
from each run variation of wc invocation:
wc -l test.txt Output: 20
awk '{print $0}' /tmp/test.txt | wc -l Output: 21
cut /tmp/test.txt -f1 | wc -l Output: 21
Similarly, when I read file from a python program I get 21 line count.
File, test.txt (attached here with) could be missing last "new line".
Thanks
Seva
[Message part 2 (text/html, inline)]
[test.txt.gz (application/x-gzip, attachment)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#23190
; Package
coreutils
.
(Sat, 02 Apr 2016 20:41:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 23190 <at> debbugs.gnu.org (full text, mbox):
tags 23190 notabug
close 23190
thanks
Hello Seva,
On 04/01/2016 06:02 PM, Seva Adari wrote:
> I am not sure if this a bug or expected behavior! Here is different output
> from each run variation of wc invocation:
> wc -l test.txt Output: 20
> awk '{print $0}' /tmp/test.txt | wc -l Output: 21
> cut /tmp/test.txt -f1 | wc -l Output: 21
[...]
>
> File, test.txt (attached here with) could be missing last "new line".
This is not a bug in 'wc', but the way it works (perhaps not intuitively):
'wc' does not count conceptual lines but the number of newline characters in the file.
Since the last file does not have a newline character (ASCII 0x10) - it is not counted.
The following will demonstrate:
$ printf "hello" | wc -l
0
$ printf "hello\n" | wc -l
1
$ printf "a\nb\nc" | wc -l
2
And 'awk' indeed automatically adds a newline when using 'print', like so:
$ printf "a\nb\nc" | awk '{print $0}' | wc -l
3
I'm therefore closing the bug, but discussion can continue by replying to this thread.
regards,
- assaf
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#23190
; Package
coreutils
.
(Thu, 07 Apr 2016 21:22:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 23190 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Thanks for the explanation!
On Sat, Apr 2, 2016 at 4:40 PM, Assaf Gordon <assafgordon <at> gmail.com> wrote:
> tags 23190 notabug
> close 23190
> thanks
>
> Hello Seva,
>
> On 04/01/2016 06:02 PM, Seva Adari wrote:
>
>> I am not sure if this a bug or expected behavior! Here is different output
>> from each run variation of wc invocation:
>> wc -l test.txt Output: 20
>> awk '{print $0}' /tmp/test.txt | wc -l Output: 21
>> cut /tmp/test.txt -f1 | wc -l Output: 21
>>
> [...]
>
>>
>> File, test.txt (attached here with) could be missing last "new line".
>>
>
> This is not a bug in 'wc', but the way it works (perhaps not intuitively):
>
> 'wc' does not count conceptual lines but the number of newline characters
> in the file.
> Since the last file does not have a newline character (ASCII 0x10) - it is
> not counted.
>
> The following will demonstrate:
>
> $ printf "hello" | wc -l
> 0
> $ printf "hello\n" | wc -l
> 1
> $ printf "a\nb\nc" | wc -l
> 2
>
> And 'awk' indeed automatically adds a newline when using 'print', like so:
>
> $ printf "a\nb\nc" | awk '{print $0}' | wc -l
> 3
>
>
> I'm therefore closing the bug, but discussion can continue by replying to
> this thread.
>
> regards,
> - assaf
>
>
[Message part 2 (text/html, inline)]
Added tag(s) notabug.
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Sat, 27 Oct 2018 22:12:01 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
23190 <at> debbugs.gnu.org and Seva Adari <oddissyus <at> gmail.com>
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Sat, 27 Oct 2018 22:12:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 25 Nov 2018 12:24:12 GMT)
Full text and
rfc822 format available.
This bug report was last modified 6 years and 292 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.