Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: autoload variables
On Thu, Sep 2, 2021 at 4:10 PM Anthony Fletcher <anthony@xxxxxxxx> wrote:
>
> > > > sed -n -e '/^default/ s/^default.*dev //; s/ .*// p;q'
To start out with, if this is GNU sed, that trailing ";q" means that
at most one line will be processed, and then sed will stop. So this
is going to print either one or zero lines. One line will be printed
if s/ .*//p matches the first line of input, otherwise nothing will
be.
In front of that, /^default/ means to consider lines that begin with
default as candidates for s/^default.*dev// -- but lines that don't
match /^default/ also won't have anything changed by that s///, so
either it should move on to the s///p and then q(uit).
> 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.
If that's true, then you have not accurately copy-pasted your sed
command in the original example.
If the command were this:
sed -n -e '/^default/{s/^default.*dev //; s/ .*// p;q;}'
Then the braces group the expressions that are separated by
semicolons, and you'll skip every line up to the first one that
matches /^default/ and then apply the two s/// to that before quitting
(again with exactly one or zero lines of output). In that instance
the leading /^default/ matters.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author