Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"I prefer rogues to imbeciles, because they sometimes take a rest." -- Alexandre Dumas (fils)


devel / comp.unix.shell / sed: -e expression #1, char 0: unmatched `{'

SubjectAuthor
* sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
+- Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
+- Re: sed: -e expression #1, char 0: unmatched `{'Ed Morton
+* Re: sed: -e expression #1, char 0: unmatched `{'Janis Papanagnou
|+- Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
|`* Re: sed: -e expression #1, char 0: unmatched `{'Geoff Clare
| +* Re: sed: -e expression #1, char 0: unmatched `{'Kenny McCormack
| |+* Re: sed: -e expression #1, char 0: unmatched `{'Ben Bacarisse
| ||`* Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
| || `* Re: sed: -e expression #1, char 0: unmatched `{'Ben Bacarisse
| ||  `- Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
| |`- Re: sed: -e expression #1, char 0: unmatched `{'Geoff Clare
| `* Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
|  `- Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
`* Re: sed: -e expression #1, char 0: unmatched `{'Helmut Waitzmann
 `* Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
  `* Re: sed: -e expression #1, char 0: unmatched `{'Helmut Waitzmann
   `* Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
    +* Re: sed: -e expression #1, char 0: unmatched `{'Oğuz
    |`- Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com
    `* Re: sed: -e expression #1, char 0: unmatched `{'Helmut Waitzmann
     `- Re: sed: -e expression #1, char 0: unmatched `{'hongy...@gmail.com

1
sed: -e expression #1, char 0: unmatched `{'

<7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4739&group=comp.unix.shell#4739

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:2409:: with SMTP id fv9mr3215755qvb.24.1639478256421;
Tue, 14 Dec 2021 02:37:36 -0800 (PST)
X-Received: by 2002:a05:622a:40d:: with SMTP id n13mr4845724qtx.511.1639478256265;
Tue, 14 Dec 2021 02:37:36 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 14 Dec 2021 02:37:36 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=143.198.81.107; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 143.198.81.107
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
Subject: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Tue, 14 Dec 2021 10:37:36 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 15
 by: hongy...@gmail.com - Tue, 14 Dec 2021 10:37 UTC

Based on the trick given here [1], I tried with the following examples:

werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
1st bar
Unrelated
2nd foo
3rd foo
werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
sed: -e expression #1, char 0: unmatched `{'

As you can see, the 2nd fails. Any hints for fixing it?

[1] https://stackoverflow.com/a/33416489

Regards,
HZ

Re: sed: -e expression #1, char 0: unmatched `{'

<6a7c23b4-8a5e-49f4-90b1-6fb4a21fae3cn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4740&group=comp.unix.shell#4740

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ae9:edd3:: with SMTP id c202mr3360825qkg.274.1639480872843;
Tue, 14 Dec 2021 03:21:12 -0800 (PST)
X-Received: by 2002:a05:6214:23c8:: with SMTP id hr8mr4497596qvb.79.1639480872681;
Tue, 14 Dec 2021 03:21:12 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 14 Dec 2021 03:21:12 -0800 (PST)
In-Reply-To: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.146; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.146
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6a7c23b4-8a5e-49f4-90b1-6fb4a21fae3cn@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Tue, 14 Dec 2021 11:21:12 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 35
 by: hongy...@gmail.com - Tue, 14 Dec 2021 11:21 UTC

On Tuesday, December 14, 2021 at 6:37:39 PM UTC+8, hongy...@gmail.com wrote:
> Based on the trick given here [1], I tried with the following examples:
>
> werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> 1st bar
> Unrelated
> 2nd foo
> 3rd foo
> werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> sed: -e expression #1, char 0: unmatched `{'

To be more specific, see my following further testings:

werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/;' -e ':c' -e '$!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
1st bar
Unrelated
2nd foo
3rd foo

werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
1st bar
Unrelated
2nd foo
3rd foo

werner@X10DAi-00:~$ sed -E -e '/foo/ {a \bar' -e ':c' -e '$!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
1st foo
bar
Unrelated
2nd foo
3rd foo

So, why can't I merge the script fragments introduced by `-e' into one for some cases?

Regards,
HZ

Re: sed: -e expression #1, char 0: unmatched `{'

<spa7al$7mb$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4741&group=comp.unix.shell#4741

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Tue, 14 Dec 2021 07:48:04 -0600
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <spa7al$7mb$1@dont-email.me>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 14 Dec 2021 13:48:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="55c7df8a04ec89c5b2ceb126dc65ff63";
logging-data="7883"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yZjYAr1yMc8KekbB4KXqe"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:Or3DhsPRbNKYgmZfUHd3o8PZzm8=
In-Reply-To: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 211214-0, 12/13/2021), Outbound message
 by: Ed Morton - Tue, 14 Dec 2021 13:48 UTC

On 12/14/2021 4:37 AM, hongy...@gmail.com wrote:
> Based on the trick given here [1], I tried with the following examples:
>
> werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'

Why are you messing around with these horrifying sed incantations?
Whatever it is you're trying to do can be done some combination of more
clearly, efficiently, robustly, portably, etc. by using awk instead.
Literally since the mid 1980s if you're using sed constructs other than
s, g, and p (with -n) then you're using the wrong tool.

Ed.

> 1st bar
> Unrelated
> 2nd foo
> 3rd foo
> werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> sed: -e expression #1, char 0: unmatched `{'
>
> As you can see, the 2nd fails. Any hints for fixing it?
>
> [1] https://stackoverflow.com/a/33416489
>
> Regards,
> HZ

Re: sed: -e expression #1, char 0: unmatched `{'

<spa97g$mfp$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4742&group=comp.unix.shell#4742

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Tue, 14 Dec 2021 15:20:31 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <spa97g$mfp$1@dont-email.me>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 14 Dec 2021 14:20:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="139716b3e327dc38000e791d5017f9a6";
logging-data="23033"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xkkbzFEZqonrGXCs4hWfK"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:rCRkZYHXHqvvQy0yYQMDU5VWw0w=
In-Reply-To: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 14 Dec 2021 14:20 UTC

On 14.12.2021 11:37, hongy...@gmail.com wrote:
> Based on the trick given here [1], I tried with the following examples:
>
> werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> 1st bar
> Unrelated
> 2nd foo
> 3rd foo
> werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> sed: -e expression #1, char 0: unmatched `{'
>
> As you can see, the 2nd fails. Any hints for fixing it?

You seem to think that several -e arguments will be textually
concatenated. - Are you sure that is the case? (I don't know,
but wouldn't expect so.)

Where from is this defunct second call syntax that you posted
above?

From your answers to my two questions you can probably derive
the answer to your own question yourself.

Janis

>
> [1] https://stackoverflow.com/a/33416489
>
> Regards,
> HZ
>

Re: sed: -e expression #1, char 0: unmatched `{'

<651953a4-0683-45c9-9c62-02db4a55e3e2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4748&group=comp.unix.shell#4748

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:59c9:: with SMTP id f9mr10363327qtf.581.1639546184251;
Tue, 14 Dec 2021 21:29:44 -0800 (PST)
X-Received: by 2002:ad4:5b8c:: with SMTP id 12mr9536348qvp.83.1639546184121;
Tue, 14 Dec 2021 21:29:44 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 14 Dec 2021 21:29:43 -0800 (PST)
In-Reply-To: <spa97g$mfp$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=165.22.62.56; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 165.22.62.56
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com> <spa97g$mfp$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <651953a4-0683-45c9-9c62-02db4a55e3e2n@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 15 Dec 2021 05:29:44 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 26
 by: hongy...@gmail.com - Wed, 15 Dec 2021 05:29 UTC

On Tuesday, December 14, 2021 at 10:20:37 PM UTC+8, Janis Papanagnou wrote:
> On 14.12.2021 11:37, hongy...@gmail.com wrote:
> > Based on the trick given here [1], I tried with the following examples:
> >
> > werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> > 1st bar
> > Unrelated
> > 2nd foo
> > 3rd foo
> > werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> > sed: -e expression #1, char 0: unmatched `{'
> >
> > As you can see, the 2nd fails. Any hints for fixing it?
> You seem to think that several -e arguments will be textually
> concatenated. - Are you sure that is the case? (I don't know,
> but wouldn't expect so.)

I'm not sure, and that's my question: Sometimes they work, sometimes not by this concatenation.
> Where from is this defunct second call syntax that you posted
> above?

As you can see, I used `{` and `}` with matching numbers in the code. So, I really don't know where the problem comes from.

HZ

Re: sed: -e expression #1, char 0: unmatched `{'

<459p8i-6h8.ln1@ID-313840.user.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4751&group=comp.unix.shell#4751

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: geo...@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Wed, 15 Dec 2021 14:02:44 +0000
Lines: 19
Message-ID: <459p8i-6h8.ln1@ID-313840.user.individual.net>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<spa97g$mfp$1@dont-email.me>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net i5OOXoewini7uPRdY5DYMgd8TqtGbVzpA1RcGkYNuNuGiKz1ye
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:Bx0x+DLZwuTPkCpDDKVdx30tu1Q=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Wed, 15 Dec 2021 14:02 UTC

Janis Papanagnou wrote:

> You seem to think that several -e arguments will be textually
> concatenated. - Are you sure that is the case? (I don't know,
> but wouldn't expect so.)

Here's what POSIX says:

If any -e or -f options are specified, the script of editing
commands shall initially be empty. The commands specified by
each -e or -f option shall be added to the script in the order
specified. When each addition is made, if the previous addition
(if any) was from a -e option, a <newline> shall be inserted
before the new addition.

The inserted <newline> is the important factor here.

--
Geoff Clare <netnews@gclare.org.uk>

Re: sed: -e expression #1, char 0: unmatched `{'

<83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4752&group=comp.unix.shell#4752

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!fXGZDwDYzNao4KoDWRce3Q.user.46.165.242.75.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Wed, 15 Dec 2021 16:01:17 +0100
Organization: Aioe.org NNTP Server
Message-ID: <83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="5216"; posting-host="fXGZDwDYzNao4KoDWRce3Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:tYeTldNHoLKtcgTKG/QOWfjCXoA=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
X-Notice: Filtered by postfilter v. 0.9.2
Mail-Copies-To: nobody
 by: Helmut Waitzmann - Wed, 15 Dec 2021 15:01 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com>:
>werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
>1st bar
>Unrelated
>2nd foo
>3rd foo
>werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
>sed: -e expression #1, char 0: unmatched `{'
>
>As you can see, the 2nd fails. Any hints for fixing it?
>

Read the 'sed' manual carefully (or should I say, cautious?),
especially the description of the 'a' command.  The POSIX manual of
the 'sed' utility might be helpful as well (see
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03>).

Or, try to answer the question:  How would you let the 'a' command
output a line ending with a semicolon?

Re: sed: -e expression #1, char 0: unmatched `{'

<spd3tl$1t53c$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4753&group=comp.unix.shell#4753

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Wed, 15 Dec 2021 16:08:21 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <spd3tl$1t53c$1@news.xmission.com>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com> <spa97g$mfp$1@dont-email.me> <459p8i-6h8.ln1@ID-313840.user.individual.net>
Injection-Date: Wed, 15 Dec 2021 16:08:21 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2004076"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 15 Dec 2021 16:08 UTC

In article <459p8i-6h8.ln1@ID-313840.user.individual.net>,
Geoff Clare <netnews@gclare.org.uk> wrote:
>Janis Papanagnou wrote:
>
>> You seem to think that several -e arguments will be textually
>> concatenated. - Are you sure that is the case? (I don't know,
>> but wouldn't expect so.)
>
>Here's what POSIX says:

But they aren't really 'concatenated'; each has to internally complete.

Observe:

$ sed -e ifoo
blue
foo
blue
^C
$ sed -e i -e foo
sed: -e expression #1, char 1: expected \ after `a', `c' or `i'
$

--
The people who were, are, and always will be, wrong about everything, are still
calling *us* "libtards"...

(John Fugelsang)

Re: sed: -e expression #1, char 0: unmatched `{'

<871r2dztt2.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4754&group=comp.unix.shell#4754

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Wed, 15 Dec 2021 17:01:13 +0000
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <871r2dztt2.fsf@bsb.me.uk>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<spa97g$mfp$1@dont-email.me>
<459p8i-6h8.ln1@ID-313840.user.individual.net>
<spd3tl$1t53c$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="5f596f9237df6631f4c71dc6171515d7";
logging-data="21460"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/k1C6D8PgYRzO84g/BWkL6aNzjQZcqf58="
Cancel-Lock: sha1:Yybmsx7W+XIHWPNSlCctHwI6m1o=
sha1:qpBVM24WQPIlze1TdzxMyIdEJA8=
X-BSB-Auth: 1.c8149cdd9f00f30d0a35.20211215170113GMT.871r2dztt2.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 15 Dec 2021 17:01 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:

> In article <459p8i-6h8.ln1@ID-313840.user.individual.net>,
> Geoff Clare <netnews@gclare.org.uk> wrote:
>>Janis Papanagnou wrote:
>>
>>> You seem to think that several -e arguments will be textually
>>> concatenated. - Are you sure that is the case? (I don't know,
>>> but wouldn't expect so.)
>>
>>Here's what POSIX says:
>
> But they aren't really 'concatenated'; each has to internally
> complete.

Why did you start "but" and then snip the very clear explanation of
what's happening?

> Observe:
>
> $ sed -e ifoo
> blue
> foo
> blue
> ^C
> $ sed -e i -e foo
> sed: -e expression #1, char 1: expected \ after `a', `c' or `i'
> $

It would have been more helpful to say "yes" and give an example of how
the inserted newline makes multiple commands work:

$ echo xyz | sed -n -e '1=' -e '$='
1 1
$ echo xyz | sed -n -e '1=$='
sed: -e expression #1, char 3: extra characters after command
$ echo xyz | sed -n -e '1=
$='
1 1
$

--
Ben.

Re: sed: -e expression #1, char 0: unmatched `{'

<a5d9051b-8682-4dcd-a20e-ffb697e16fcen@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4755&group=comp.unix.shell#4755

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:2c9:: with SMTP id a9mr14856914qtx.28.1639611817436;
Wed, 15 Dec 2021 15:43:37 -0800 (PST)
X-Received: by 2002:a05:622a:91:: with SMTP id o17mr14477613qtw.48.1639611817187;
Wed, 15 Dec 2021 15:43:37 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Wed, 15 Dec 2021 15:43:37 -0800 (PST)
In-Reply-To: <871r2dztt2.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.91.163; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.91.163
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<spa97g$mfp$1@dont-email.me> <459p8i-6h8.ln1@ID-313840.user.individual.net>
<spd3tl$1t53c$1@news.xmission.com> <871r2dztt2.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a5d9051b-8682-4dcd-a20e-ffb697e16fcen@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 15 Dec 2021 23:43:37 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 46
 by: hongy...@gmail.com - Wed, 15 Dec 2021 23:43 UTC

On Thursday, December 16, 2021 at 1:01:18 AM UTC+8, Ben Bacarisse wrote:
> gaz...@shell.xmission.com (Kenny McCormack) writes:
>
> > In article <459p8i-...@ID-313840.user.individual.net>,
> > Geoff Clare <net...@gclare.org.uk> wrote:
> >>Janis Papanagnou wrote:
> >>
> >>> You seem to think that several -e arguments will be textually
> >>> concatenated. - Are you sure that is the case? (I don't know,
> >>> but wouldn't expect so.)
> >>
> >>Here's what POSIX says:
> >
> > But they aren't really 'concatenated'; each has to internally
> > complete.
> Why did you start "but" and then snip the very clear explanation of
> what's happening?
> > Observe:
> >
> > $ sed -e ifoo
> > blue
> > foo
> > blue
> > ^C
> > $ sed -e i -e foo
> > sed: -e expression #1, char 1: expected \ after `a', `c' or `i'
> > $
> It would have been more helpful to say "yes" and give an example of how
> the inserted newline makes multiple commands work:
>
> $ echo xyz | sed -n -e '1=' -e '$='
> 1
> 1
> $ echo xyz | sed -n -e '1=$='
> sed: -e expression #1, char 3: extra characters after command
> $ echo xyz | sed -n -e '1=
> $='
> 1
> 1
> $

Good catch and wonderful example. But the content of echo doesn't matter here at all:

$ echo | sed -n -e '1=
$='
1 1

Re: sed: -e expression #1, char 0: unmatched `{'

<f5218849-be65-4edc-a398-fa1ea423aba7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4756&group=comp.unix.shell#4756

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a0c:8031:: with SMTP id 46mr13687618qva.126.1639611922066;
Wed, 15 Dec 2021 15:45:22 -0800 (PST)
X-Received: by 2002:a05:622a:170e:: with SMTP id h14mr14590859qtk.479.1639611921941;
Wed, 15 Dec 2021 15:45:21 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Wed, 15 Dec 2021 15:45:21 -0800 (PST)
In-Reply-To: <83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de>
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.91.163; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.91.163
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com> <83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f5218849-be65-4edc-a398-fa1ea423aba7n@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 15 Dec 2021 23:45:22 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 20
 by: hongy...@gmail.com - Wed, 15 Dec 2021 23:45 UTC

On Wednesday, December 15, 2021 at 11:01:25 PM UTC+8, Helmut Waitzmann wrote:
> "hongy...@gmail.com" <hongy...@gmail.com>:
> >werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> >1st bar
> >Unrelated
> >2nd foo
> >3rd foo
> >werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> >sed: -e expression #1, char 0: unmatched `{'
> >
> >As you can see, the 2nd fails. Any hints for fixing it?
> >
> Read the 'sed' manual carefully (or should I say, cautious?),
> especially the description of the 'a' command. The POSIX manual of
> the 'sed' utility might be helpful as well (see
> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03>).
>
> Or, try to answer the question: How would you let the 'a' command
> output a line ending with a semicolon?

I looked through the POSIX manual of 'sed' you linked above, but still in the dark.

Re: sed: -e expression #1, char 0: unmatched `{'

<e375268f-1d68-4dd8-92c4-442ee2f30244n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4757&group=comp.unix.shell#4757

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:199a:: with SMTP id bm26mr10924091qkb.542.1639611972706;
Wed, 15 Dec 2021 15:46:12 -0800 (PST)
X-Received: by 2002:ad4:5b8c:: with SMTP id 12mr13589406qvp.83.1639611972608;
Wed, 15 Dec 2021 15:46:12 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Wed, 15 Dec 2021 15:46:12 -0800 (PST)
In-Reply-To: <459p8i-6h8.ln1@ID-313840.user.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.91.163; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.91.163
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<spa97g$mfp$1@dont-email.me> <459p8i-6h8.ln1@ID-313840.user.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e375268f-1d68-4dd8-92c4-442ee2f30244n@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 15 Dec 2021 23:46:12 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 20
 by: hongy...@gmail.com - Wed, 15 Dec 2021 23:46 UTC

On Wednesday, December 15, 2021 at 10:11:07 PM UTC+8, Geoff Clare wrote:
> Janis Papanagnou wrote:
>
> > You seem to think that several -e arguments will be textually
> > concatenated. - Are you sure that is the case? (I don't know,
> > but wouldn't expect so.)
> Here's what POSIX says:

Where did you find these specifications?
> If any -e or -f options are specified, the script of editing
> commands shall initially be empty. The commands specified by
> each -e or -f option shall be added to the script in the order
> specified. When each addition is made, if the previous addition
> (if any) was from a -e option, a <newline> shall be inserted
> before the new addition.
>
> The inserted <newline> is the important factor here.
>
> --
> Geoff Clare <net...@gclare.org.uk>

Re: sed: -e expression #1, char 0: unmatched `{'

<d7b51b3e-7bbd-4f2d-a223-4828daa6530en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4758&group=comp.unix.shell#4758

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:5a84:: with SMTP id c4mr14637586qtc.565.1639612814312;
Wed, 15 Dec 2021 16:00:14 -0800 (PST)
X-Received: by 2002:a05:6214:d08:: with SMTP id 8mr13872129qvh.46.1639612814210;
Wed, 15 Dec 2021 16:00:14 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Wed, 15 Dec 2021 16:00:13 -0800 (PST)
In-Reply-To: <e375268f-1d68-4dd8-92c4-442ee2f30244n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.91.163; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.91.163
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<spa97g$mfp$1@dont-email.me> <459p8i-6h8.ln1@ID-313840.user.individual.net> <e375268f-1d68-4dd8-92c4-442ee2f30244n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d7b51b3e-7bbd-4f2d-a223-4828daa6530en@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 16 Dec 2021 00:00:14 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 22
 by: hongy...@gmail.com - Thu, 16 Dec 2021 00:00 UTC

On Thursday, December 16, 2021 at 7:46:15 AM UTC+8, hongy...@gmail.com wrote:
> On Wednesday, December 15, 2021 at 10:11:07 PM UTC+8, Geoff Clare wrote:
> > Janis Papanagnou wrote:
> >
> > > You seem to think that several -e arguments will be textually
> > > concatenated. - Are you sure that is the case? (I don't know,
> > > but wouldn't expect so.)
> > Here's what POSIX says:
> Where did you find these specifications?
> > If any -e or -f options are specified, the script of editing
> > commands shall initially be empty. The commands specified by
> > each -e or -f option shall be added to the script in the order
> > specified. When each addition is made, if the previous addition
> > (if any) was from a -e option, a <newline> shall be inserted
> > before the new addition.
> >

I find these specifications here: <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03>
> > The inserted <newline> is the important factor here.
> >
> > --
> > Geoff Clare <net...@gclare.org.uk>

Re: sed: -e expression #1, char 0: unmatched `{'

<874k79xrql.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4759&group=comp.unix.shell#4759

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Thu, 16 Dec 2021 01:28:50 +0000
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <874k79xrql.fsf@bsb.me.uk>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<spa97g$mfp$1@dont-email.me>
<459p8i-6h8.ln1@ID-313840.user.individual.net>
<spd3tl$1t53c$1@news.xmission.com> <871r2dztt2.fsf@bsb.me.uk>
<a5d9051b-8682-4dcd-a20e-ffb697e16fcen@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b9f7989dd930ff4732a641e9d197fd11";
logging-data="29087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jDXkttEyutpzIGFuGOGGdnDKquXejuM4="
Cancel-Lock: sha1:WaLld2w3R13Ug9Is+3YI4lRmsr8=
sha1:rk4jzY9D/oT4LpxFU5D9Gf1e74o=
X-BSB-Auth: 1.bc03b50aef78c832c7bc.20211216012850GMT.874k79xrql.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 16 Dec 2021 01:28 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:

> On Thursday, December 16, 2021 at 1:01:18 AM UTC+8, Ben Bacarisse wrote:
>> gaz...@shell.xmission.com (Kenny McCormack) writes:
>>
>> > In article <459p8i-...@ID-313840.user.individual.net>,
>> > Geoff Clare <net...@gclare.org.uk> wrote:
>> >>Janis Papanagnou wrote:
>> >>
>> >>> You seem to think that several -e arguments will be textually
>> >>> concatenated. - Are you sure that is the case? (I don't know,
>> >>> but wouldn't expect so.)
>> >>
>> >>Here's what POSIX says:
>> >
>> > But they aren't really 'concatenated'; each has to internally
>> > complete.
>> Why did you start "but" and then snip the very clear explanation of
>> what's happening?
>> > Observe:
>> >
>> > $ sed -e ifoo
>> > blue
>> > foo
>> > blue
>> > ^C
>> > $ sed -e i -e foo
>> > sed: -e expression #1, char 1: expected \ after `a', `c' or `i'
>> > $
>> It would have been more helpful to say "yes" and give an example of how
>> the inserted newline makes multiple commands work:
>>
>> $ echo xyz | sed -n -e '1=' -e '$='
>> 1
>> 1
>> $ echo xyz | sed -n -e '1=$='
>> sed: -e expression #1, char 3: extra characters after command
>> $ echo xyz | sed -n -e '1=
>> $='
>> 1
>> 1
>> $
>
> Good catch and wonderful example. But the content of echo doesn't matter here at all:
>
> $ echo | sed -n -e '1=
> $='
> 1
> 1

Except for clarity. echo on it's own echos a newline so the input to
sed has one empty line. In general, it's not a good idea to used
examples that have such hidden details. echo zyx obviously generates a
line. echo on it's own also does, but not it's not so obvious.

--
Ben.

Re: sed: -e expression #1, char 0: unmatched `{'

<e553c6f6-47da-407b-8bc6-3ff7df0645ccn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4760&group=comp.unix.shell#4760

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a0c:8e08:: with SMTP id v8mr9682990qvb.93.1639627150269;
Wed, 15 Dec 2021 19:59:10 -0800 (PST)
X-Received: by 2002:a37:2713:: with SMTP id n19mr11034833qkn.375.1639627150105;
Wed, 15 Dec 2021 19:59:10 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Wed, 15 Dec 2021 19:59:09 -0800 (PST)
In-Reply-To: <874k79xrql.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.91.163; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.91.163
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<spa97g$mfp$1@dont-email.me> <459p8i-6h8.ln1@ID-313840.user.individual.net>
<spd3tl$1t53c$1@news.xmission.com> <871r2dztt2.fsf@bsb.me.uk>
<a5d9051b-8682-4dcd-a20e-ffb697e16fcen@googlegroups.com> <874k79xrql.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e553c6f6-47da-407b-8bc6-3ff7df0645ccn@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 16 Dec 2021 03:59:10 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 16
 by: hongy...@gmail.com - Thu, 16 Dec 2021 03:59 UTC

On Thursday, December 16, 2021 at 9:28:55 AM UTC+8, Ben Bacarisse wrote:
> > $ echo | sed -n -e '1=
> > $='
> > 1
> > 1
> Except for clarity. echo on it's own echos a newline so the input to
> sed has one empty line. In general, it's not a good idea to used
> examples that have such hidden details. echo zyx obviously generates a
> line. echo on it's own also does, but not it's not so obvious.

Thank you for your additional explanation, I add the following example as a further example to improve your above point of view:

$ echo -e 'a\nb\nc' | sed -n -e '1=' -e '$='
1 3

Re: sed: -e expression #1, char 0: unmatched `{'

<30sr8i-18k.ln1@ID-313840.user.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4761&group=comp.unix.shell#4761

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: geo...@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Thu, 16 Dec 2021 13:36:35 +0000
Lines: 52
Message-ID: <30sr8i-18k.ln1@ID-313840.user.individual.net>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<spa97g$mfp$1@dont-email.me> <459p8i-6h8.ln1@ID-313840.user.individual.net>
<spd3tl$1t53c$1@news.xmission.com>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net PLgU9lbxfSuFrCut3+T2YQcjoL6YCXwA3Hu0m6QcRtMZQxVps6
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:SoWwPeHV4chPmrckUZaTi0PataA=
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
 by: Geoff Clare - Thu, 16 Dec 2021 13:36 UTC

Kenny McCormack wrote:

> In article <459p8i-6h8.ln1@ID-313840.user.individual.net>,
> Geoff Clare <netnews@gclare.org.uk> wrote:
>>Janis Papanagnou wrote:
>>
>>> You seem to think that several -e arguments will be textually
>>> concatenated. - Are you sure that is the case? (I don't know,
>>> but wouldn't expect so.)
>>
>>Here's what POSIX says:
>
> But they aren't really 'concatenated'; each has to internally complete.
>
> Observe:
>
> $ sed -e ifoo
> blue
> foo
> blue
> ^C
> $ sed -e i -e foo
> sed: -e expression #1, char 1: expected \ after `a', `c' or `i'
> $

I guess you missed the bit (that you didn't quote) of my post about
the inserted <newline>.

sed -e i -e foo

would be equivalent to:

sed -e 'i
foo'

which is invalid. Whereas the equivalent of the valid command:

sed -e 'i\
foo'

split into two -e option-arguments is:

sed -e 'i\' -e foo

and works fine:

$ echo blue | sed -e 'i\' -e foo
foo
blue

--
Geoff Clare <netnews@gclare.org.uk>

Re: sed: -e expression #1, char 0: unmatched `{'

<83lf0kf8h6.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4762&group=comp.unix.shell#4762

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!U5qIIZRYx+YhnbgOZWs0sQ.user.46.165.242.75.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Fri, 17 Dec 2021 00:14:29 +0100
Organization: Aioe.org NNTP Server
Message-ID: <83lf0kf8h6.fsf@helmutwaitzmann.news.arcor.de>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de>
<f5218849-be65-4edc-a398-fa1ea423aba7n@googlegroups.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="38068"; posting-host="U5qIIZRYx+YhnbgOZWs0sQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mail-Copies-To: nobody
Cancel-Lock: sha1:Nmc9AI1smt65M/n6ece26YkRL4g=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Helmut Waitzmann - Thu, 16 Dec 2021 23:14 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com>:
> On Wednesday, December 15, 2021 at 11:01:25 PM UTC+8, Helmut Waitzmann wrote:
>
>> "hongy...@gmail.com" <hongy...@gmail.com>:
>>> werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
>>> 1st bar
>>> Unrelated
>>> 2nd foo
>>> 3rd foo
>>> werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
>>> sed: -e expression #1, char 0: unmatched `{'
>>>
>>> As you can see, the 2nd fails. Any hints for fixing it?
>>>
>>>
>> Read the 'sed' manual carefully (or should I say, cautious?),
>> especially the description of the 'a' command. The POSIX manual of
>> the 'sed' utility might be helpful as well (see
>> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03>).
>>
>> Or, try to answer the question: How would you let the 'a' command
>> output a line ending with a semicolon?
>
> I looked through the POSIX manual of 'sed' you linked above, but
> still in the dark.

Ok.  Do you understand the English language?  Then, please, read
the following quote from the POSIX manual linked above:

'Editing commands other than {...}, a, b, c, i, r, t, w, :, and #
can be followed by a <semicolon>, optional <blank> characters, and
another editing command.'

What is the implication of this sentence in combination with the
whole section of the POSIX manual linked above with regard to the
'a' command?  Yes:  The 'a' command CANNOT BE FOLLOWED BY A
SEMICOLON…

Now, look at your testing above:  What are you doing there?

Sorry, but this is basic language understanding.  If you don't obey
the rules, you shouldn't be surprised when they strike back.

Re: sed: -e expression #1, char 0: unmatched `{'

<f3ff298e-b385-4713-a19f-4a35e444b95dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4763&group=comp.unix.shell#4763

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ad4:58cf:: with SMTP id dh15mr580812qvb.125.1639706017720;
Thu, 16 Dec 2021 17:53:37 -0800 (PST)
X-Received: by 2002:a05:6214:400c:: with SMTP id kd12mr689630qvb.41.1639706017588;
Thu, 16 Dec 2021 17:53:37 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Thu, 16 Dec 2021 17:53:37 -0800 (PST)
In-Reply-To: <83lf0kf8h6.fsf@helmutwaitzmann.news.arcor.de>
Injection-Info: google-groups.googlegroups.com; posting-host=165.22.62.56; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 165.22.62.56
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de> <f5218849-be65-4edc-a398-fa1ea423aba7n@googlegroups.com>
<83lf0kf8h6.fsf@helmutwaitzmann.news.arcor.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f3ff298e-b385-4713-a19f-4a35e444b95dn@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Fri, 17 Dec 2021 01:53:37 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 63
 by: hongy...@gmail.com - Fri, 17 Dec 2021 01:53 UTC

On Friday, December 17, 2021 at 7:20:09 AM UTC+8, Helmut Waitzmann wrote:
> "hongy...@gmail.com" <hongy...@gmail.com>:
> > On Wednesday, December 15, 2021 at 11:01:25 PM UTC+8, Helmut Waitzmann wrote:
> >
> >> "hongy...@gmail.com" <hongy...@gmail.com>:
> >>> werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> >>> 1st bar
> >>> Unrelated
> >>> 2nd foo
> >>> 3rd foo
> >>> werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> >>> sed: -e expression #1, char 0: unmatched `{'
> >>>
> >>> As you can see, the 2nd fails. Any hints for fixing it?
> >>>
> >>>
> >> Read the 'sed' manual carefully (or should I say, cautious?),
> >> especially the description of the 'a' command. The POSIX manual of
> >> the 'sed' utility might be helpful as well (see
> >> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03>).
> >>
> >> Or, try to answer the question: How would you let the 'a' command
> >> output a line ending with a semicolon?
> >
> > I looked through the POSIX manual of 'sed' you linked above, but
> > still in the dark.
> Ok. Do you understand the English language? Then, please, read
> the following quote from the POSIX manual linked above:
>
> 'Editing commands other than {...}, a, b, c, i, r, t, w, :, and #
> can be followed by a <semicolon>, optional <blank> characters, and
> another editing command.'
>
> What is the implication of this sentence in combination with the
> whole section of the POSIX manual linked above with regard to the
> 'a' command? Yes: The 'a' command CANNOT BE FOLLOWED BY A
> SEMICOLON…

I just browse the entire content linked by you with searching the literal `;' instead of trying to find the wording `<semicolon>' used there. This makes it impossible for me to quickly find the explanation you pointed out above.


> Now, look at your testing above: What are you doing there?

But with or without the `;', the same error will be triggered:

$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
sed: -e expression #1, char 0: unmatched `{'

$ sed -E -e '/foo/ {a \ bar :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
sed: -e expression #1, char 0: unmatched `{'

> Sorry, but this is basic language understanding. If you don't obey
> the rules, you shouldn't be surprised when they strike back.

Agree. That should be the expected behavior, if so.

Re: sed: -e expression #1, char 0: unmatched `{'

<sph5l9$tkq$1@oguzismail.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4765&group=comp.unix.shell#4765

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!oguzismail.eternal-september.org!.POSTED!not-for-mail
From: oguzisma...@gmail.com (Oğuz)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Fri, 17 Dec 2021 08:02:31 +0300
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <sph5l9$tkq$1@oguzismail.eternal-september.org>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de>
<f5218849-be65-4edc-a398-fa1ea423aba7n@googlegroups.com>
<83lf0kf8h6.fsf@helmutwaitzmann.news.arcor.de>
<f3ff298e-b385-4713-a19f-4a35e444b95dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Dec 2021 05:02:33 -0000 (UTC)
Injection-Info: oguzismail.eternal-september.org; posting-host="0155d7f8944b3f69a5f49a37c64b352a";
logging-data="30362"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18z017BCljilZxRMwaJRE3AHPA8lYuwL3I="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:iIicu69a0Ukv5XnV0uUdwhIG8t8=
In-Reply-To: <f3ff298e-b385-4713-a19f-4a35e444b95dn@googlegroups.com>
Content-Language: en-US
 by: Oğuz - Fri, 17 Dec 2021 05:02 UTC

On 12/17/21 4:53 AM, hongy...@gmail.com wrote:
> But with or without the `;', the same error will be triggered:
>
> $ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> sed: -e expression #1, char 0: unmatched `{'
>
> $ sed -E -e '/foo/ {a \ bar :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> sed: -e expression #1, char 0: unmatched `{'

The `a\' command needs to be terminated with a line break, not a blank
or a semicolon you moron.

$ sed -E -e '/foo/ {a \ bar
> :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
1st foo
bar
Unrelated
2nd foo
3rd foo
$

Re: sed: -e expression #1, char 0: unmatched `{'

<a210fb15-6464-415c-82fb-be71db38f90an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4766&group=comp.unix.shell#4766

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:7942:: with SMTP id r2mr1338247qtt.303.1639729657464;
Fri, 17 Dec 2021 00:27:37 -0800 (PST)
X-Received: by 2002:a05:620a:288c:: with SMTP id j12mr1008880qkp.66.1639729657272;
Fri, 17 Dec 2021 00:27:37 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Fri, 17 Dec 2021 00:27:37 -0800 (PST)
In-Reply-To: <sph5l9$tkq$1@oguzismail.eternal-september.org>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.44; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.44
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de> <f5218849-be65-4edc-a398-fa1ea423aba7n@googlegroups.com>
<83lf0kf8h6.fsf@helmutwaitzmann.news.arcor.de> <f3ff298e-b385-4713-a19f-4a35e444b95dn@googlegroups.com>
<sph5l9$tkq$1@oguzismail.eternal-september.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a210fb15-6464-415c-82fb-be71db38f90an@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Fri, 17 Dec 2021 08:27:37 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 42
 by: hongy...@gmail.com - Fri, 17 Dec 2021 08:27 UTC

On Friday, December 17, 2021 at 1:02:38 PM UTC+8, Oğuz wrote:
> On 12/17/21 4:53 AM, hongy...@gmail.com wrote:
> > But with or without the `;', the same error will be triggered:
> >
> > $ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> > sed: -e expression #1, char 0: unmatched `{'
> >
> > $ sed -E -e '/foo/ {a \ bar :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> > sed: -e expression #1, char 0: unmatched `{'
> The `a\' command needs to be terminated with a line break, not a blank
> or a semicolon you moron.
> $ sed -E -e '/foo/ {a \ bar
> > :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> 1st foo
> bar
> Unrelated
> 2nd foo
> 3rd foo
> $

Thank you for pointing this out. I didn't realize that the command format in the manual page already contained the usage information you mentioned above:

$ man sed | grep -A2 ' \\$' | grep -v '^--'
a \

text Append text, which has each embedded newline preceded by a backslash.
i \

text Insert text, which has each embedded newline preceded by a backslash.
c \

text Replace the selected lines with text, which has each embedded newline preceded by a backslash.

So, all the above three commands need to be terminated with a line break.

HZ

Re: sed: -e expression #1, char 0: unmatched `{'

<83wnk3dl95.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4775&group=comp.unix.shell#4775

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!XEZabSweYSa4RHL+xNioKA.user.46.165.242.75.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
Date: Fri, 17 Dec 2021 21:33:42 +0100
Organization: Aioe.org NNTP Server
Message-ID: <83wnk3dl95.fsf@helmutwaitzmann.news.arcor.de>
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de>
<f5218849-be65-4edc-a398-fa1ea423aba7n@googlegroups.com>
<83lf0kf8h6.fsf@helmutwaitzmann.news.arcor.de>
<f3ff298e-b385-4713-a19f-4a35e444b95dn@googlegroups.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="8602"; posting-host="XEZabSweYSa4RHL+xNioKA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:mmX3yOMOkI6fE5Fwf3ck+xO0UoE=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
X-Notice: Filtered by postfilter v. 0.9.2
Mail-Copies-To: nobody
 by: Helmut Waitzmann - Fri, 17 Dec 2021 20:33 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com>:
> On Friday, December 17, 2021 at 7:20:09 AM UTC+8, Helmut Waitzmann wrote:
>
>> "hongy...@gmail.com" <hongy...@gmail.com>:
>>> On Wednesday, December 15, 2021 at 11:01:25 PM UTC+8, Helmut Waitzmann wrote:
>>>
>>>> "hongy...@gmail.com" <hongy...@gmail.com>:
>>>>> werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
>>>>> 1st bar
>>>>> Unrelated
>>>>> 2nd foo
>>>>> 3rd foo
>>>>> werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
>>>>> sed: -e expression #1, char 0: unmatched `{'
>>>>>
>>>>> As you can see, the 2nd fails. Any hints for fixing it?
>>>>>
>>>>>
>>>> Read the 'sed' manual carefully (or should I say, cautious?),
>>>> especially the description of the 'a' command. The POSIX manual
>>>> of the 'sed' utility might be helpful as well (see
>>>> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03>).
>>>>
>>>> Or, try to answer the question: How would you let the 'a'
>>>> command output a line ending with a semicolon?
>>>
>>> I looked through the POSIX manual of 'sed' you linked above, but
>>> still in the dark.
>> Ok. Do you understand the English language? Then, please, read
>> the following quote from the POSIX manual linked above:
>>
>> 'Editing commands other than {...}, a, b, c, i, r, t, w, :, and #
>> can be followed by a <semicolon>, optional <blank> characters, and
>> another editing command.'
>>
>> What is the implication of this sentence in combination with the
>> whole section of the POSIX manual linked above with regard to the
>> 'a' command? Yes: The 'a' command CANNOT BE FOLLOWED BY A
>> SEMICOLON…
>
> I just browse the entire content linked by you with searching the
> literal `;' instead of trying to find the wording `<semicolon>'
> used there. This makes it impossible for me to quickly find the
> explanation you pointed out above.

That's true, indeed.  It's the difference between browsing and
(carefully) reading.

But I didn't want you to search the text for semicolons (neither
the symbol nor the word).  I supposed, that you either read the
given section of the manual or (without reading the manual) just
asked yourself the question:  How would one let the 'a' command
output a line ending with a semicolon?

To answer that question:  The developers of the 'sed' program were
quite silly, if they had designed an 'a' command in such a way,
that it were not possible to let it output a line ending with a
semicolon.

The consequence of this statement is, that the 'a' command cannot
look like this example:

a \ This is a line to be appended, ending in a period.;

i. e.  the semicolon cannot be used as an 'a' command terminator,
as that would it make impossible to have a semicolon be part of a
line to be appended by the 'a' command.

And at this point you could indeed read the manual.  For to make
your life easier, I gave you a link with an anchor (i. e. the
'#tag_20_116_13_03' part of the URL), which should position your
browser at the relevant section of the manual.

That's, what I called reading the manual carefully or even
cautiously.

>
>
>> Now, look at your testing above: What are you doing there?
>>

To give the answer:  Your example assumes, that a semicolon can be
used as an 'a' command terminator.  The consequence of this is, that
you assume, that the developers of the 'sed' program where quite
silly when designing the 'a' command.

>
> But with or without the `;', the same error will be triggered:
>

That's by coincidence, just like switching the christmas tree
lights on won't work regardless of the colors of the bulbs if the
fuse has been burnt out.

The problem in your example is not the semicolon (be it present or
not); it's the missing newline after the intended 'a' command,
which will let the 'a' command continue til the end of the 'sed'
invocation argument.  Therefore even the two '}' will be part of
the 'a' command, "eating" the '}' that was intended to match the
'{' immediately preceding the 'a' command, thus leaving the '{'
unmatched:

> $ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> sed: -e expression #1, char 0: unmatched `{'
>
> $ sed -E -e '/foo/ {a \ bar :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> sed: -e expression #1, char 0: unmatched `{'
>

To see a difference with or without the first semicolon in the
invocation argument, add a newline and the missing '}' to each
variant to make it a syntactically valid 'sed' script.  Run the two
variants:

printf '%s\n' '1st foo' 'Unrelated' '2nd foo' '3rd foo' |
sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}
}'

printf '%s\n' '1st foo' 'Unrelated' '2nd foo' '3rd foo' |
sed -E -e '/foo/ {a \ bar :c $!{n;bc}}
}'

(I prefer the posixly 'printf' over the not‐yet‐posixly shell
syntax $'…' and the posixly pipeline over non‐posixly here‐strings
(<<<) to have the examples work with any posixly environment.)

Re: sed: -e expression #1, char 0: unmatched `{'

<edb0f970-4991-4590-8d30-63d2d78d9117n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4777&group=comp.unix.shell#4777

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:7252:: with SMTP id l18mr5247492qtp.9.1639801433877;
Fri, 17 Dec 2021 20:23:53 -0800 (PST)
X-Received: by 2002:ad4:5b8c:: with SMTP id 12mr4890295qvp.83.1639801433731;
Fri, 17 Dec 2021 20:23:53 -0800 (PST)
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Fri, 17 Dec 2021 20:23:53 -0800 (PST)
In-Reply-To: <83wnk3dl95.fsf@helmutwaitzmann.news.arcor.de>
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.91.163; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.91.163
References: <7d6ce42f-791b-45c7-afc8-7a1c5e9a2effn@googlegroups.com>
<83bl1hhpz6.fsf@helmutwaitzmann.news.arcor.de> <f5218849-be65-4edc-a398-fa1ea423aba7n@googlegroups.com>
<83lf0kf8h6.fsf@helmutwaitzmann.news.arcor.de> <f3ff298e-b385-4713-a19f-4a35e444b95dn@googlegroups.com>
<83wnk3dl95.fsf@helmutwaitzmann.news.arcor.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <edb0f970-4991-4590-8d30-63d2d78d9117n@googlegroups.com>
Subject: Re: sed: -e expression #1, char 0: unmatched `{'
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sat, 18 Dec 2021 04:23:53 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 130
 by: hongy...@gmail.com - Sat, 18 Dec 2021 04:23 UTC

On Saturday, December 18, 2021 at 4:36:45 AM UTC+8, Helmut Waitzmann wrote:
> "hongy...@gmail.com" <hongy...@gmail.com>:
> > On Friday, December 17, 2021 at 7:20:09 AM UTC+8, Helmut Waitzmann wrote:
> >
> >> "hongy...@gmail.com" <hongy...@gmail.com>:
> >>> On Wednesday, December 15, 2021 at 11:01:25 PM UTC+8, Helmut Waitzmann wrote:
> >>>
> >>>> "hongy...@gmail.com" <hongy...@gmail.com>:
> >>>>> werner@X10DAi-00:~$ sed -E -e '/foo/ {s//bar/; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> >>>>> 1st bar
> >>>>> Unrelated
> >>>>> 2nd foo
> >>>>> 3rd foo
> >>>>> werner@X10DAi-00:~$ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> >>>>> sed: -e expression #1, char 0: unmatched `{'
> >>>>>
> >>>>> As you can see, the 2nd fails. Any hints for fixing it?
> >>>>>
> >>>>>
> >>>> Read the 'sed' manual carefully (or should I say, cautious?),
> >>>> especially the description of the 'a' command. The POSIX manual
> >>>> of the 'sed' utility might be helpful as well (see
> >>>> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03>).
> >>>>
> >>>> Or, try to answer the question: How would you let the 'a'
> >>>> command output a line ending with a semicolon?
> >>>
> >>> I looked through the POSIX manual of 'sed' you linked above, but
> >>> still in the dark.
> >> Ok. Do you understand the English language? Then, please, read
> >> the following quote from the POSIX manual linked above:
> >>
> >> 'Editing commands other than {...}, a, b, c, i, r, t, w, :, and #
> >> can be followed by a <semicolon>, optional <blank> characters, and
> >> another editing command.'
> >>
> >> What is the implication of this sentence in combination with the
> >> whole section of the POSIX manual linked above with regard to the
> >> 'a' command? Yes: The 'a' command CANNOT BE FOLLOWED BY A
> >> SEMICOLON…
> >
> > I just browse the entire content linked by you with searching the
> > literal `;' instead of trying to find the wording `<semicolon>'
> > used there. This makes it impossible for me to quickly find the
> > explanation you pointed out above.
> That's true, indeed. It's the difference between browsing and
> (carefully) reading.
>
> But I didn't want you to search the text for semicolons (neither
> the symbol nor the word). I supposed, that you either read the
> given section of the manual or (without reading the manual) just
> asked yourself the question: How would one let the 'a' command
> output a line ending with a semicolon?
> To answer that question: The developers of the 'sed' program were
> quite silly, if they had designed an 'a' command in such a way,
> that it were not possible to let it output a line ending with a
> semicolon.
>
> The consequence of this statement is, that the 'a' command cannot
> look like this example:
>
> a \ This is a line to be appended, ending in a period.;
>
> i. e. the semicolon cannot be used as an 'a' command terminator,
> as that would it make impossible to have a semicolon be part of a
> line to be appended by the 'a' command.
>
> And at this point you could indeed read the manual. For to make
> your life easier, I gave you a link with an anchor (i. e. the
> '#tag_20_116_13_03' part of the URL), which should position your
> browser at the relevant section of the manual.
>
> That's, what I called reading the manual carefully or even
> cautiously.
> >
> >
> >> Now, look at your testing above: What are you doing there?
> >>
> To give the answer: Your example assumes, that a semicolon can be
> used as an 'a' command terminator. The consequence of this is, that
> you assume, that the developers of the 'sed' program where quite
> silly when designing the 'a' command.
> >
> > But with or without the `;', the same error will be triggered:
> >
> That's by coincidence, just like switching the christmas tree
> lights on won't work regardless of the colors of the bulbs if the
> fuse has been burnt out.
>
> The problem in your example is not the semicolon (be it present or
> not); it's the missing newline after the intended 'a' command,
> which will let the 'a' command continue til the end of the 'sed'
> invocation argument. Therefore even the two '}' will be part of
> the 'a' command, "eating" the '}' that was intended to match the
> '{' immediately preceding the 'a' command, thus leaving the '{'
> unmatched:
>
> > $ sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> > sed: -e expression #1, char 0: unmatched `{'
> >
> > $ sed -E -e '/foo/ {a \ bar :c $!{n;bc}}' <<<$'1st foo\nUnrelated\n2nd foo\n3rd foo'
> > sed: -e expression #1, char 0: unmatched `{'
> >
> To see a difference with or without the first semicolon in the
> invocation argument, add a newline and the missing '}' to each
> variant to make it a syntactically valid 'sed' script. Run the two
> variants:
>
> printf '%s\n' '1st foo' 'Unrelated' '2nd foo' '3rd foo' |
> sed -E -e '/foo/ {a \ bar; :c $!{n;bc}}
> }'
> printf '%s\n' '1st foo' 'Unrelated' '2nd foo' '3rd foo' |
> sed -E -e '/foo/ {a \ bar :c $!{n;bc}}
> }'
> (I prefer the posixly 'printf' over the not‐yet‐posixly shell
> syntax $'…' and the posixly pipeline over non‐posixly here‐strings
> (<<<) to have the examples work with any posixly environment.)

Thank you for providing insightful and wonderful examples and explanations.

HZ

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor