John Doe, on 2018-10-14:
> Hi,

Good Day,

> With gawk I'm able to do the following:
>
> $ gawk -v pattern=try '$0 ~ "\\<"pattern"\\>"{getline;print $2}'
> ~/.ssh/config
> ~/.ssh/try/id_rsa
>
> $ cat ~/.ssh/config
> Host try
> IdentityFile ~/.ssh/try/id_rsa
>
> I don't want to install extra pkgs on Debian Stretch (9).
> Googling around didn't turn out something useful.
>
> Does anyone has any idea on how I can emulate the above using
> mawk?

No idea how to use mawk to emulate the behavior you describe; it
is far from being gawk.  However you can refine something
looking like that, to /not/ make use of gawk:

        pattern=try
        grep -A1 -E "\<${pattern}\>" \
        | tail -n-1 \
        | mawk '{print $2}'

I get the following, if this is what you expect:

        $ pattern=try grep -A1 -E "\<${pattern}\>" | tail -n-1 | mawk '{print 
$2}'
        Host try
        IdentityFile ~/.ssh/try/id_rsa^D
        ~/.ssh/try/id_rsa

Feels a bit like Wily the coyote maybe, I'm pretty much certain
it can be done simpler...  :-)

Kind Regards,
-- 
Étienne Mollier <etienne.moll...@mailoo.org>


Reply via email to