6.7. Known incompatibilities between sed versions
6.7.1. Issuing commands from the command line
Most versions of sed permit multiple commands to issued on the
command line, separated by a semicolon (;). Thus,
sed 'G;G' file
should triple-space a file. However, for non-GNU sed, some commands
require separate expressions on the command line. These include:
- all labels (':a', ':more', etc.)
- all branching instructions ('b', 't')
- commands to read and write files ('r' and 'w')
- any closing brace, '}'
If these commands are used, they must be the LAST commands of an
expression. Subsequent commands must use another expression
(another -e switch plus arguments). E.g.,
sed -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\( *\)\1/\1/' files
GNU sed, ssed, sed15 and sed16 all permit these commands to be
followed by a semicolon, so the previous script can be written:
sed ':a;s/^.\{1,77\}$/ &/;ta;s/\( *\)\1/\1/' files
Versions differ in implementing the 'a' (append), 'c' (change), and
'i' (insert) commands:
sed "/foo/i New text here" # HHsed/sedmod/gsed-30280
gsed -e "/foo/i\\" -e "New text here" # GNU sed
sed1 -e "/foo/i" -e "New text here" # one version of sed
sed2 "/foo/i\ New text here" # another version