ever need to calculate your powers of two but only have ed(1) on hand?
H
a
#######
.
s/./&&/g
s/./\
&\
/g
g/^$/.,$s/./&&/g
g/^$/d
g/^/0a\
l
g/^l/,s/#$/#$/\
,s/#\([0-9]\)/#$\1/\
,s/##########/\&/g\
,s/#########\$/9/g\
,s/########\$/8/g\
,s/#######\$/7/g\
,s/######\$/6/g\
,s/#####\$/5/g\
,s/####\$/4/g\
,s/###\$/3/g\
,s/##\$/2/g\
,s/#\$/1/g\
,s/\$/0/g\
,s/&/#/g
g/^l/d
,n
Q
POSIX incompatibiltiies
technically s with no match is an error, but no ed implementation does it like that within g. you could probably hack together a "fail line" at the end of your file that is guaranteed to have all of the substitutions you want to make on it and then discarded after.