Subject: bug#30829: (no subject)

From: "Don Crissti" <[email-masked]>
Date: Fri, 16 Mar 2018 01:39:45 +0100

Damn... No, it's not confusing at all. It's actually crystal clear. Not sure what I was thinking...

I even knew that the 1st line of a range is never checked against the 2nd RE, that's why stuff like

sed '1,/RE/d'

deletes all the lines when the only RE match is on the 1st line.

I guess my ADHD got the best of me...

Thanks for your time and for your detailed explanation !

There is a subtle issue here:
when using 2 addresses, and the second address is an RE,
the first line matching the first address (line 2 in your case)
will *never* be checked against the RE.

And so, even though the '//!d' is run conditionally,
the condition is true (line 2, before regex is checked),
and then '//!d' is executed but there is no 'last regex' yet.

This is documented in the manual:
https://www.gnu.org/software/sed/manual/sed.html#Range-Addresses
(in the second paragraph, starting with "if the second address is a regexp").

Also,
In the POSIX standard, the relevant text is:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
(under "addresses in sed" section).

"An editing command with two addresses shall select the inclusive
range from the first pattern space that matches the first address
through the next pattern space that matches the second. "

The interpretation is that the second address is checked against
"the next pattern space" - impling that the first time the second
address is checkd is not in the first line that matches, but
on the 'next pattern space' (meaning starting at the line following
the line that matched the first address).
[phew, that is a bit confusing....]

Does this clarify the issue?

-assaf