GNU bug report logs - #77786
GNU sed in POSIX mode sometimes not matching newlines

Previous Next

Package: sed;

Reported by: Wolfgang Jeltsch <wolfgang <at> well-typed.com>

Date: Sun, 13 Apr 2025 21:30:02 UTC

Severity: normal

To reply to this bug, email your comments to 77786 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-sed <at> gnu.org:
bug#77786; Package sed. (Sun, 13 Apr 2025 21:30:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Wolfgang Jeltsch <wolfgang <at> well-typed.com>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Sun, 13 Apr 2025 21:30:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Wolfgang Jeltsch <wolfgang <at> well-typed.com>
To: bug-sed <at> gnu.org
Subject: GNU sed in POSIX mode sometimes not matching newlines
Date: Sun, 13 Apr 2025 23:41:30 +0300
Hi!

I’m using GNU sed 4.9 under Ubuntu 24.04.2, and I think I’ve found a bug
in it.

Consider the following shell command:

    echo 'A
    B
    C' | sed -E 'N; N; s/^A\n[[:alpha:]]\n*/XXX/'

Executing this results in the following output:

    XXXC

This is what I would expect.

However, when I run the same command but with GNU sed in POSIX
compatibility mode, by either setting POSIXLY_CORRECT to a non-empty
value or inserting the argument `--posix` into the `sed` invocation,
then I get the following output:

    XXX
    C

I cannot see a reason for this to be considered a correct result, and
I’m quite sure that it violates the POSIX standard.

What’s more, that difference between GNU and POSIX mode does not show up
with slightly simplified examples. Consider the following commands:

    echo 'B
    C' | sed -E 'N; s/^[[:alpha:]]\n*/XXX/'

    echo 'A
    B
    C' | sed -E 'N; N; s/^A\nB\n*/XXX/'

Both result in the following output, no matter whether POSIX
compatibility is requested or not:

    XXXC

This is what I’m considering the correct result.

All the best,
Wolfgang




This bug report was last modified 10 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.