GNU bug report logs -
#77786
GNU sed in POSIX mode sometimes not matching newlines
Previous Next
Full log
View this message in rfc822 format
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 63 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.