tag 82124 notabug
close 82124
stop
On 27/10/2026 20:29, Mark Symmes wrote:
I am running Linux 7.2.6-76070206-generic.
I have discovered that the 'wc' command functions strictly as a newline-byte
counter rather than a logical line counter.
The issue has been around since maybe 1970 but I could be wrong. Maybe FreeBSD
has addressed the issue.
I am suggesting a new flag that would help in detecting what I will find a
'dangling line-feed' that proceeds an EOF.
The proof is running a python3 script vs a bash awk script.
The reason for this is to be consistent no matter
how the inputs are combined:
$ { printf '1\n2'; printf '1\n2'; } | wc -l --total=only
2
$ wc -l --total=only <(printf '1\n2') <(printf '1\n2')
2
$ { printf '1\n2'; printf '1\n2'; } | awk 'END{print NR}'
3
$ awk 'END{print NR}' <(printf '1\n2') <(printf '1\n2')
4
Given this is long standing cross POSIX defined behavior,
it would not be appropriate to change.
Note one could preprocess files to ensure they're
a POSIX defined text file (trailing newline) with something like:
ensure_text() { sed '$a\'; }
cheers,
Padraig