On Wed, Dec 05, 2018 at 08:09:30AM +0100, Andreas Kusalananda Kähäri wrote:
> On Wed, Dec 05, 2018 at 06:14:34AM +0200, Lars Noodén wrote:
> > I'm noticing some trouble with branching in sed(1) now.  Leaving the
> > label empty should branch to the end of the script:
> > 
> >       [2addr]b [label]
> >              Branch to the : function with the specified label.  If the 
> > label
> >              is not specified, branch to the end of the script.
> > 
> > However, in practice, when I try branching without a label, I get an
> > error about an undefined label instead of it branching to the end of
> > the script:
> > 
> > $ echo -e "START\nfoo\nbar\nEND\nbaz\n" | sed -n '/^START/,/^END/b;p;'
> > sed: 1: "/^START/,/^END/b;p;": undefined label ''
> > 
> > Adding a label works as expected:
> > 
> > $ echo -e "START\nfoo\nbar\nEND\nbaz\n" | sed -n '/^START/,/^END/ba;p;:a;
> 
> No, adding the newlines makes it work.  The label has nothing to do with
> it.

Sorry, too early in the morning to be reading code and make a difference
between code and data, inserting a label seems to make it work (but
I'm unsure why; sure, it's convenient, but why do we have it?)  Still,
a portable sed script should have a newline after the "b" (and ":")
commands, not a semicolon.

> 
> The label (empty or not) has to be delimited by a newline.  In your
> first script, you could also have used
> 
>     sed -n -e '/^START/,/^END/b' -e p
> 
> (each -e inserts a newline in the script), or more simply
> 
>     sed '/^START/,/^END/d'
> 
> This is AFAIK standard behaviour.
> 
> >From POSIX:
> 
>     Command verbs other than {, a, b, c, i, r, t, w, :, and # can be
>     followed by a <semicolon>, optional <blank> characters, and
>     another command verb.
> 
> 
> Andreas
> 
> > 
> > If I have not made a mistake with the short script above then there
> > seems to be a discrepancy between the behavior described in the manual
> > and the actual behavior.
> > 
> > dmesg below
> > /Lars
> > 
[cut]

-- 
Andreas Kusalananda Kähäri,
National Bioinformatics Infrastructure Sweden (NBIS),
Uppsala University, Sweden.

Reply via email to