Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: autoload variables



> > > Le Tue, Aug 31, 2021 at 11:03:39PM +0200, Roman Perepelitsa a écrit :
> > > english is fine. can you confirm that '/^default/ s/^default.*dev //'
> > > is a suttered way to say              's/^default.*dev //' ?
> > 
> > Yes, these are equivalent. Anything that matches '^default.*dev '
> > matches '^default'.
> 
> Yes but the point is I am only interested in lines that start with
> 'default via'. I am ignoring all the other lines. Without the initial
> match /^default/ all the other lines are processed by the
> substitutions and I get the wrong interface.

there is no point of repeating yourself without leaving the lhs part
empty. What you just wrote is

* find default at the begin of the line
* find it *again then let's substitute something containing default

if you wanted to ignore a line, your sed script miss the d command
(i used it in the version i proposed):

    /^default/d
        stop the processing of this line (including the default p ending)
        if it match.
    /^default/!d
        stop the processing of this line (including the default p ending)
        if *don't* match.

also: sed keeps the track of its last match which can be called with an
empty lhs. so:

    /^default.*dev/!d ; s///

means:
* don't process the lines that don't match the pattern
* as it matched, remove the matched part

> > This requires a new-enough version of ip to support json output.
> Cool - I didn't know JSON output was an option. Not that jq is much less
> baroque than sed.  I think this is better than my sed script.

* sed is for text.
* jq is for datastructures serialized in json (i wish there will be a
  cbor backend at some point).

> One point in favour of sed - it's then on all systems, jq isn't.

sed is made to be a simple tool inside a pipe or from an editor: it
completes an ecosystem.

jq is a good query langage (baroque as well) but just for json.

> Sorry for the off-topic discussion.

this is my "fault" as i was the one who asked for your sed command.
To me this isn't off-topic at all: zsh is about gluing commands
and sed is both powerful and popular enough so any zsh user should
know a bit of sed.

regards
marc




Messages sorted by: Reverse Date, Date, Thread, Author