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 `{'
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
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
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?
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.)
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?
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:
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'
$
On Wednesday, December 15, 2021 at 10:11:07 PM UTC+8, Geoff Clare wrote:
Janis Papanagnou wrote:
Where did you find these specifications?You seem to think that several -e arguments will be textually concatenated. - Are you sure that is the case? (I don't know,Here's what POSIX says:
but wouldn't expect so.)
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>
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 internallyWhy did you start "but" and then snip the very clear explanation of
complete.
what's happening?
Observe:
$ sed -e ifooIt would have been more helpful to say "yes" and give an example of how
blue
foo
blue
^C
$ sed -e i -e foo
sed: -e expression #1, char 1: expected \ after `a', `c' or `i'
$
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
$
"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?
Janis Papanagnou wrote:
You seem to think that several -e arguments will be textuallyHere's what POSIX says:
concatenated. - Are you sure that is the case? (I don't know,
but wouldn't expect so.)
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>
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>,Why did you start "but" and then snip the very clear explanation of
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.
what's happening?
Observe:It would have been more helpful to say "yes" and give an example of how
$ 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 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
$ echo | sed -n -e '1=Except for clarity. echo on it's own echos a newline so the input to
$='
1
1
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.
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'
$
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'Read the 'sed' manual carefully (or should I say, cautious?),
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?
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.
"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'Read the 'sed' manual carefully (or should I say, cautious?),
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?
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, butOk. Do you understand the English language? Then, please, read
still in the dark.
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.
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 `{'
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'The `a\' command needs to be terminated with a line break, not a blank
sed: -e expression #1, char 0: unmatched `{'
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
$
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:Ok. Do you understand the English language? Then, please, read
"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'Read the 'sed' manual carefully (or should I say, cautious?),
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?
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.
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 `{'
"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:Ok. Do you understand the English language? Then, please, read
"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'Read the 'sed' manual carefully (or should I say, cautious?),
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?
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.
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 theThat's true, indeed. It's the difference between browsing and
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.
(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.
To give the answer: Your example assumes, that a semicolon can beNow, look at your testing above: What are you doing there?
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.)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 79:47:14 |
Calls: | 6,658 |
Calls today: | 4 |
Files: | 12,203 |
Messages: | 5,333,092 |
Posted today: | 1 |