bug-sed
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#30829: bug: empty regex exits with error when following 2-address li


From: Assaf Gordon
Subject: bug#30829: bug: empty regex exits with error when following 2-address like LINENO, /RE/
Date: Thu, 15 Mar 2018 17:16:34 -0600
User-agent: Mutt/1.5.24 (2015-08-30)

Follow-up:

On Thu, Mar 15, 2018 at 04:34:07PM -0600, Assaf Gordon wrote:
> On Thu, Mar 15, 2018 at 09:20:37PM +0100, Don Crissti wrote:
[...]
> >    # printf %s\\n {1..5} | sed '2,/5/{//!d}'
> > 
> >    fails with
> > 
> >    "sed: -e expression #1, char 0: no previous regular expression"
> [...]
> And the interpertation (of both GNU sed >4.0 and *BSD's sed) is
> that the "last RE used in the last command *applied*" means the last RE 
> *executed*
> - not the last regex that preceeds the empty regex in the program.

The previous examples were needlessly complicated.
Here's a simpler example:

  $ printf "%s\n" ccbb aabb | sed -e '/a/!s/b/X/' -e 's//*/'           
  ccX*
  *abb

Whether the 'last regex' is /a/ or /b/ depends on whether the line
contains 'a' or not.
 
> I therefore think this is not a bug (and I'm marking it as 'done').
> However discussion can continue by replying to this thread,
> and if there are different opinions we can always re-open it.

One could argue that the behavior you're expecting (and happens
in sed-heirloom and sed-gnu-3.02) is that if there is no "last regex"
silently treat it as 'no match'.

That's easy to implement but I don't think that's a good change.
The current behaviour is better.

More so, I suspect sed-heirloom's behavior is just buggy:

  $ seq 1 | sed-heirloom -n -e '2p' -e '//p'
  [no output]

  $ seq 2 | sed-heirloom -n -e '2p' -e '//p'
  2
  2

  $ seq 2 | sed-heirloom -n -e '2,5p' -e '//p'
  2

  $ seq 2 | sed-heirloom -n -e '//p'
  First RE may not be null


regards,
 - assaf






reply via email to

[Prev in Thread] Current Thread [Next in Thread]