Let us use the Sed POSIX standard to answer the questions.
Does the spacing around the semicolon make any real difference?
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.
Thus /^$/d ; $!G
is not compliant, but /^$/d; $!G
is. But I do wonder if
there is any modern Sed implementation that would stumble on that.
Is there any real difference (universality, compliance...) between any of the three syntaxes listed above?
No (except for the one with spaces before the semicolon, as argued above).
This is clear in the synopsis:
sed [-n] script [file...]
sed [-n] -e script [-e script]... [-f script_file]... [file...]
Do note, however, that as the previous quote mentioned, some commands cannot
be followed by a semicolon, and then
sed -e ':a' -e 's/x/y/' -e 't a'
is compliant, while
sed ':a;s/x/y;t a'
is not, although but work the same at least in GNU Sed.
My hunch is that (...) using both -e
and ;
on the command line is redundant. Am I correct?
If you refer to the examples in the question, yes. If there is a single -e
option, then just drop it and it is all the same (unless you also use the
-f
option (see the synopsis)). But in
sed -e ':a' -e 's/x/y;t a'
both -e
and ;
are present but they are not redundant.
Best Answer
With GNU
sed
(and probably others), you can give multiple commands separated by a semicolon:Other
sed
implementations might need you to give the two commands separately with-e
:Finally, you could also combine them into a
sed
script:Then, you run it with
-f
: