[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

While we're talking about new features

From: Andrew L. Moore
Subject: While we're talking about new features
Date: Fri, 7 Jan 2022 21:28:32 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1

| 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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]