Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #201208 > unrolled thread
| Started by | john doe <johndoe65534@mail.com> |
|---|---|
| First post | 2018-10-14 10:20 +0200 |
| Last post | 2018-10-14 13:50 +0200 |
| Articles | 6 — 2 participants |
Back to article view | Back to linux.debian.user
Word-boundary mawk Debian Stretch john doe <johndoe65534@mail.com> - 2018-10-14 10:20 +0200
Re: Word-boundary mawk Debian Stretch Étienne Mollier <etienne.mollier@mailoo.org> - 2018-10-14 13:30 +0200
Re: Word-boundary mawk Debian Stretch john doe <johndoe65534@mail.com> - 2018-10-14 13:50 +0200
Re: Word-boundary mawk Debian Stretch Étienne Mollier <etienne.mollier@mailoo.org> - 2018-10-14 14:00 +0200
Re: Word-boundary mawk Debian Stretch john doe <johndoe65534@mail.com> - 2018-10-15 13:40 +0200
Re: Word-boundary mawk Debian Stretch john doe <johndoe65534@mail.com> - 2018-10-14 13:50 +0200
| From | john doe <johndoe65534@mail.com> |
|---|---|
| Date | 2018-10-14 10:20 +0200 |
| Subject | Word-boundary mawk Debian Stretch |
| Message-ID | <wIJMZ-8uZ-1@gated-at.bofh.it> |
Hi,
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?
--
John Doe
[toc] | [next] | [standalone]
| From | Étienne Mollier <etienne.mollier@mailoo.org> |
|---|---|
| Date | 2018-10-14 13:30 +0200 |
| Message-ID | <wIMKS-1LW-3@gated-at.bofh.it> |
| In reply to | #201208 |
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.mollier@mailoo.org>
[toc] | [prev] | [next] | [standalone]
| From | john doe <johndoe65534@mail.com> |
|---|---|
| Date | 2018-10-14 13:50 +0200 |
| Message-ID | <wIN4e-1S0-9@gated-at.bofh.it> |
| In reply to | #201211 |
On 10/14/2018 1:24 PM, Étienne Mollier wrote:
> 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... :-)
>
Thank you, I was hoping for something with less pipes redirection but
given that portability is required, I might as wel go that way! :)
--
John Doe
[toc] | [prev] | [next] | [standalone]
| From | Étienne Mollier <etienne.mollier@mailoo.org> |
|---|---|
| Date | 2018-10-14 14:00 +0200 |
| Message-ID | <wINdT-1V5-5@gated-at.bofh.it> |
| In reply to | #201213 |
On 10/14/18 1:47 PM, john doe wrote:
> Thank you, I was hoping for something with less pipes redirection but
> given that portability is required, I might as wel go that way! :)
Sure, one less:
$ pattern=try grep -A1 -E "\<${pattern}\>" | mawk '{getline;print $2;exit}'
(in) noise
(in) Host try
(in) IdentityFile ~/.ssh/try/id_rsa1
(in) noise
(in) Host try
(in) IdentityFile ~/.ssh/try/id_rsa2
(in) noise
(out) ~/.ssh/try/id_rsa1
and it should work as expected, this time. :-)
Kind Regards,
--
Étienne Mollier <etienne.mollier@mailoo.org>
[toc] | [prev] | [next] | [standalone]
| From | john doe <johndoe65534@mail.com> |
|---|---|
| Date | 2018-10-15 13:40 +0200 |
| Message-ID | <wJ9o6-6MB-5@gated-at.bofh.it> |
| In reply to | #201214 |
On 10/14/2018 1:55 PM, Étienne Mollier wrote:
>
>
> On 10/14/18 1:47 PM, john doe wrote:
>> Thank you, I was hoping for something with less pipes redirection but
>> given that portability is required, I might as wel go that way! :)
>
> Sure, one less:
>
> $ pattern=try grep -A1 -E "\<${pattern}\>" | mawk '{getline;print $2;exit}'
> (in) noise
> (in) Host try
> (in) IdentityFile ~/.ssh/try/id_rsa1
> (in) noise
> (in) Host try
> (in) IdentityFile ~/.ssh/try/id_rsa2
> (in) noise
> (out) ~/.ssh/try/id_rsa1
>
> and it should work as expected, this time. :-)
>
It is indeed, thank you.
Here's what I've come up with:
$ grep -A1 -E "\<${1}\>" ~/.ssh/config| awk '{getline;print $2;exit}'
Argument 1 ('${1}') is used because it is in a shell script/function.
--
John Doe
[toc] | [prev] | [next] | [standalone]
| From | john doe <johndoe65534@mail.com> |
|---|---|
| Date | 2018-10-14 13:50 +0200 |
| Message-ID | <wIN4d-1S0-1@gated-at.bofh.it> |
| In reply to | #201208 |
On 10/14/2018 10:13 AM, john doe wrote:
> Hi,
>
> With gawk I'm able to do the following:
>
> $ gawk -v pattern=try '$0 ~ "\\<"pattern"\\>"{getline;print $2}'
> ~/.ssh/config
> ~/.ssh/try/id_rsa
>
I forgot in the above command 'exit' at the end of the gawk command.
So the command in question is:
$ gawk -v pattern=try '$0 ~ "\\<"pattern"\\>"{getline;print $2;exit}'
--
John Doe
[toc] | [prev] | [standalone]
Back to top | Article view | linux.debian.user
csiph-web