| Shawn Wagner wrote:
| Two more I have in mind:
| Supporting a GNU sed extension of taking both a starting offset and
| g with s///Ng - replace all matches starting with the Nth one. I
| have this mostly done; I'm not sure how it should interact with the
| current toggling behavior of sN and sg, though.
| Adding an ex-like range to ! that sends the addressed lines to an
| external command and replaces them with its output. I don't think
| there's any good way to do this now that doesn't involve multiple
| steps and a temporary file.
You might want to take a look at https://github.com/slewsys/ed. This
implements both.
The syntax of offsets differs from GNU sed as follows (from ChangeLog):
Command Interpretation
======= ==============
s/old/new/$ Replace last (regexp match of) `old'
with `new'.
s/old/new/$-1 Replace second to last `old' with `new'.
s/old/new/-1 Replace second to last `old' with `new'.
s/old/new/- Replace second to last `old' with `new'.
s/old/new/0 Replace last `old' with `new'.
s/old/new/g$ Replace last `old' with `new'.
s/old/new/$g Replace last `old' with `new'.
s/old/new/$-1g Replace last two `old' with `new'.
s/old/new/g$-1 Replace second to last `old' with
`new'. (1)
(1) See entry dated 2008-04-06 below for modifier syntax.
-AM