On 19/04/2023 13:07, наб wrote:
Package: coreutils
Version: 9.1-1
Severity: normal
Dear Maintainer,
POSIX very clearly says (Issue 8 Draft 2.1, same as Issue 7):
100982 The nl utility views the text it reads in terms of logical pages. Line
numbering shall be reset at
100983 the start of each logical page. A logical page consists of a header, a
body, and a footer section.
100984 Empty sections are valid. Different line numbering options are
independently available for
100985 header, body, and footer (for example, no numbering of header and
footer lines while
100986 numbering blank lines only in the body).
100987 The starts of logical page sections shall be signaled by input lines
containing nothing but the
100988 following delimiter characters:
100989 Line Start of
100990 \:\:\: Header
100991 \:\: Body
100992 \: Footer
100993 Unless otherwise specified, nl shall assume the text being read is in a
single logical page body.
101021 −p Specify that numbering should not be restarted at logical page
delimiters.
Indeed, both illumos-gate nl and SysVr4 nl behave like this:
-- >8 --
$ printf '%s\n' a '\:\:\:' b '\:\:' c '\:' d '\:\:\:' e '\:\:\:' f | ./a.out
-ht -ft
1 a
1 b
2 c
3 d
1 e
1 f
$ printf '%s\n' a '\:\:\:' b '\:\:' c '\:' d '\:\:\:' e '\:\:\:' f | ./a.out
-ht -ft -p
1 a
2 b
3 c
4 d
5 e
6 f
-- >8 --
But coreutils nl resets the line number at the start of each section?
-- >8 --
$ printf '%s\n' a '\:\:\:' b '\:\:' c '\:' d '\:\:\:' e '\:\:\:' f | nl -ht -ft
1 a
1 b
1 c
1 d
1 e
1 f
$ printf '%s\n' a '\:\:\:' b '\:\:' c '\:' d '\:\:\:' e '\:\:\:' f | nl -ht -ft
-p
1 a
2 b
3 c
4 d
5 e
6 f
-- >8 --
This was changed 7 years ago with:
https://lists.gnu.org/archive/html/coreutils/2016-05/msg00000.html
Now re-reading POSIX I agree with your interpretation.
I.e. reading the -p description the current coreutils behavior seems correct,
while also adding the context from the start of the POSIX doc,
your interpretation seems correct.
Note FreeBSD follows the current coreutils behavior by resetting the count at
each section,
so it is a bit ambiguous as to the correct operation.
cheers,
Pádraig