4 ms·
Note that, somewhat counter-intuitively, what "wc -l" counts is the number of newline characters: $ printf 'foo\nbar' | wc -l 1 There are arguably two lin
by jwilk 9y ago
Note that, somewhat counter-intuitively, what "wc -l" counts is the number of newline characters:
$ printf 'foo\nbar' | wc -l
1
There are arguably two lines in the input, but the result is 1.
Without this (mis)feature, "wc -l" would be more difficult to parallelize.
- LambdaComplex 9y agoThe POSIX definition of a "line" is "A sequence of zero or more non- <newline> characters plus a terminating <newline> character"[0]. I don't think it's counterintuitive at all for POSIX utilities to respect that definition. 0. http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_...
- frou_dh 9y ago"terminator, not separator" is an easy way to remember it. I would call bar in GP's comment a fragment.
- jandrese 9y agoThe only difference is you have to check the last character in the file to determine if it is a newline. Maybe the last 4 characters if it is Unicode.