Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

fortune: No such file or directory


devel / comp.lang.awk / Storing a Linux shell command into an AWK variable

SubjectAuthor
* Storing a Linux shell command into an AWK variableMr. Man-wai Chang
+* Re: Storing a Linux shell command into an AWK variableKees Nuyt
|`* Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
| `* Re: Storing a Linux shell command into an AWK variableJanis Papanagnou
|  `* Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
|   `* Re: Storing a Linux shell command into an AWK variableJanis Papanagnou
|    +* Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
|    |`* Re: Storing a Linux shell command into an AWK variableJanis Papanagnou
|    | `* Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
|    |  `* Re: Storing a Linux shell command into an AWK variableKenny McCormack
|    |   +* Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
|    |   |`* Re: Storing a Linux shell command into an AWK variableJanis Papanagnou
|    |   | `* Re: Storing a Linux shell command into an AWK variableBen Bacarisse
|    |   |  `* Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
|    |   |   `- Re: Storing a Linux shell command into an AWK variableBen Bacarisse
|    |   `- Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
|    `- Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
`* Re: Storing a Linux shell command into an AWK variableEd Morton
 `* Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
  +* Re: Storing a Linux shell command into an AWK variableKenny McCormack
  |+- Re: Storing a Linux shell command into an AWK variableJanis Papanagnou
  |`- Re: Storing a Linux shell command into an AWK variableMr. Man-wai Chang
  `- Re: Storing a Linux shell command into an AWK variableEd Morton

1
Storing a Linux shell command into an AWK variable

<urpsnh$gu7u$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1769&group=comp.lang.awk#1769

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Storing a Linux shell command into an AWK variable
Date: Thu, 29 Feb 2024 20:18:56 +0800
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <urpsnh$gu7u$1@toylet.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 29 Feb 2024 12:18:57 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="953411ffe672447eff4f799a86bfdb74";
logging-data="555262"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qtDp6WBaC444DZMoZSDC8"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:XYora8gp6Pb3SCW7r9NrpCSjCGs=
Content-Language: en-US
 by: Mr. Man-wai Chang - Thu, 29 Feb 2024 12:18 UTC

How could I store the following BASH command into an Awk variable?

**** begin *****
site_survey 2>&1 | \
sed -e 's/^./{/' \
-e 's/\] SSID\[/\} SSID\{/' \
-e 's/\] channel\[/} channel{/' \
-e 's/\] enc\[/} enc{/' \
-e 's/.$/\}/'
**** end *****

Re: Storing a Linux shell command into an AWK variable

<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1770&group=comp.lang.awk#1770

  copy link   Newsgroups: comp.lang.awk
From: k.nuyt@nospam.demon.nl (Kees Nuyt)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Thu, 29 Feb 2024 15:24:01 +0100
Reply-To: k.nuyt@nospam.demon.nl
Message-ID: <ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
User-Agent: ForteAgent/7.10.32.1214
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 34
Injection-Date: Thu, 29 Feb 2024 15:24:04 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Kees Nuyt - Thu, 29 Feb 2024 14:24 UTC

On Thu, 29 Feb 2024 20:18:56 +0800, "Mr. Man-wai Chang"
<toylet.toylet@gmail.com> wrote:

>How could I store the following BASH command into an Awk variable?
>
>**** begin *****
>site_survey 2>&1 | \
>sed -e 's/^./{/' \
>-e 's/\] SSID\[/\} SSID\{/' \
>-e 's/\] channel\[/} channel{/' \
>-e 's/\] enc\[/} enc{/' \
>-e 's/.$/\}/'
>**** end *****

Try:
myvar = "site_survey 2>&1 | \
sed -e 's/^./{/' \
-e 's/\\] SSID\\[/\\} SSID\\{/' \
-e 's/\\] channel\\[/} channel{/' \
-e 's/\\] enc\\[/} enc{/' \
-e 's/.$/\\}/'"

or, if you insist on preserving linebreaks:

myvar2 = "site_survey 2>&1 | \\\n" \
"sed -e 's/^./{/' \\\n" \
"-e 's/\\] SSID\\[/\\} SSID\\{/' \\\n" \
"-e 's/\\] channel\\[/} channel{/' \\\n" \
"-e 's/\\] enc\\[/} enc{/' \\\n" \
"-e 's/.$/\\}/'"
--
HTH
Kees Nuyt

Re: Storing a Linux shell command into an AWK variable

<urqa8j$mfmd$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1771&group=comp.lang.awk#1771

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Fri, 1 Mar 2024 00:09:54 +0800
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <urqa8j$mfmd$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 29 Feb 2024 16:09:55 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="953411ffe672447eff4f799a86bfdb74";
logging-data="736973"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6fC2DcUEMyUQROVsJFle0"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:cn5zKbYjIddqsZ9mt0kVcWBtQNk=
Content-Language: en-US
In-Reply-To: <ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
 by: Mr. Man-wai Chang - Thu, 29 Feb 2024 16:09 UTC

On 29/2/2024 10:24 pm, Kees Nuyt wrote:
> On Thu, 29 Feb 2024 20:18:56 +0800, "Mr. Man-wai Chang"
> <toylet.toylet@gmail.com> wrote:
>
>> How could I store the following BASH command into an Awk variable?
>>
>> **** begin *****
>> site_survey 2>&1 | \
>> sed -e 's/^./{/' \
>> -e 's/\] SSID\[/\} SSID\{/' \
>> -e 's/\] channel\[/} channel{/' \
>> -e 's/\] enc\[/} enc{/' \
>> -e 's/.$/\}/'
>> **** end *****
>
> Try:
> myvar = "site_survey 2>&1 | \
> sed -e 's/^./{/' \
> -e 's/\\] SSID\\[/\\} SSID\\{/' \
> -e 's/\\] channel\\[/} channel{/' \
> -e 's/\\] enc\\[/} enc{/' \
> -e 's/.$/\\}/'"
>
> or, if you insist on preserving linebreaks:
>
> myvar2 = "site_survey 2>&1 | \\\n" \
> "sed -e 's/^./{/' \\\n" \
> "-e 's/\\] SSID\\[/\\} SSID\\{/' \\\n" \
> "-e 's/\\] channel\\[/} channel{/' \\\n" \
> "-e 's/\\] enc\\[/} enc{/' \\\n" \
> "-e 's/.$/\\}/'"

Thanks!

Because of the call to sed within the Awk vaariable, need to escape:

1. "]" to "\\]"
2. "[" to "\\["
3. "'" to "'\''"

Absolutely horrifying. :)

This is what I end up with:

cmd="site_survey 2>&1 | \
sed -e '\''s/^./{/'\'' \
-e '\''s/\\] SSID\\[/\} SSID\{/'\'' \
-e '\''s/\\] channel\\[/} channel{/'\'' \
-e '\''s/\\] enc\\[/} enc{/'\'' \
-e '\''s/.$/\}/'\'' ";

Re: Storing a Linux shell command into an AWK variable

<urqehb$nfru$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1772&group=comp.lang.awk#1772

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Thu, 29 Feb 2024 18:22:50 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <urqehb$nfru$1@dont-email.me>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
<urqa8j$mfmd$1@toylet.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 29 Feb 2024 17:22:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6585c110415aecacdf06b444dafb3632";
logging-data="769918"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0ZcQ3di4v8O2U/fhFVZnC"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:vdEccTsVL1r889XuDYeyxGsW5oM=
In-Reply-To: <urqa8j$mfmd$1@toylet.eternal-september.org>
 by: Janis Papanagnou - Thu, 29 Feb 2024 17:22 UTC

On 29.02.2024 17:09, Mr. Man-wai Chang wrote:
>> On Thu, 29 Feb 2024 20:18:56 +0800, "Mr. Man-wai Chang"
>> <toylet.toylet@gmail.com> wrote:
>>
>>> How could I store the following BASH command into an Awk variable?
>>>
>>> **** begin *****
>>> site_survey 2>&1 | \
>>> sed -e 's/^./{/' \
>>> -e 's/\] SSID\[/\} SSID\{/' \
>>> -e 's/\] channel\[/} channel{/' \
>>> -e 's/\] enc\[/} enc{/' \
>>> -e 's/.$/\}/'
>>> **** end *****
[...]
>
> Thanks!
>
> Because of the call to sed within the Awk vaariable, need to escape:
>
> 1. "]" to "\\]"
> 2. "[" to "\\["
> 3. "'" to "'\''"
>
> Absolutely horrifying. :)
>
> This is what I end up with:
>
> cmd="site_survey 2>&1 | \
> sed -e '\''s/^./{/'\'' \
> -e '\''s/\\] SSID\\[/\} SSID\{/'\'' \
> -e '\''s/\\] channel\\[/} channel{/'\'' \
> -e '\''s/\\] enc\\[/} enc{/'\'' \
> -e '\''s/.$/\}/'\'' ";
>

Whenever I see this sort of question and the attempted "solution"
I'm tempted to ask whether your approach might be not be the best;
there's quite some indications. - Mind to elaborate on the task
(not technically, but as seen from a higher perspective)?

Janis

Re: Storing a Linux shell command into an AWK variable

<ursk3h$18a2o$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1773&group=comp.lang.awk#1773

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Fri, 1 Mar 2024 21:10:08 +0800
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <ursk3h$18a2o$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
<urqa8j$mfmd$1@toylet.eternal-september.org> <urqehb$nfru$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 13:10:09 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="a5dfc74f3d92357c9c3e5d43cc47f31b";
logging-data="1321048"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jWoBunxgDFy31i4kZ1PLt"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:rK+Y+UCeDBXl05xXtRwagvVbCYU=
In-Reply-To: <urqehb$nfru$1@dont-email.me>
Content-Language: en-US
 by: Mr. Man-wai Chang - Fri, 1 Mar 2024 13:10 UTC

On 1/3/2024 1:22 am, Janis Papanagnou wrote:
> On 29.02.2024 17:09, Mr. Man-wai Chang wrote:
>>> On Thu, 29 Feb 2024 20:18:56 +0800, "Mr. Man-wai Chang"
>>> <toylet.toylet@gmail.com> wrote:
>>>
>>>> How could I store the following BASH command into an Awk variable?
>>>>
>>>> **** begin *****
>>>> site_survey 2>&1 | \
>>>> sed -e 's/^./{/' \
>>>> -e 's/\] SSID\[/\} SSID\{/' \
>>>> -e 's/\] channel\[/} channel{/' \
>>>> -e 's/\] enc\[/} enc{/' \
>>>> -e 's/.$/\}/'
>>>> **** end *****
> [...]
>>
>> Thanks!
>>
>> Because of the call to sed within the Awk vaariable, need to escape:
>>
>> 1. "]" to "\\]"
>> 2. "[" to "\\["
>> 3. "'" to "'\''"
>>
>> Absolutely horrifying. :)
>>
>> This is what I end up with:
>>
>> cmd="site_survey 2>&1 | \
>> sed -e '\''s/^./{/'\'' \
>> -e '\''s/\\] SSID\\[/\} SSID\{/'\'' \
>> -e '\''s/\\] channel\\[/} channel{/'\'' \
>> -e '\''s/\\] enc\\[/} enc{/'\'' \
>> -e '\''s/.$/\}/'\'' ";
>>
>
> Whenever I see this sort of question and the attempted "solution"
> I'm tempted to ask whether your approach might be not be the best;
> there's quite some indications. - Mind to elaborate on the task
> (not technically, but as seen from a higher perspective)?

The site_survey command vomits lines:

[ 8] SSID[ [HOME]] BSSID[04:9F:xx:xx:xx:xx] channel[ 6]
frequency[2437] numsta[1] rssi[-63] noise[-75] beacon[98] cap[1411]
dtim[0] rate[450] enc[Group-AES-CCMP CCMP PSK2 ]

Just wanna change all field delimiters, which are square brackets, to
curly braces within an Awk program loop.

I agree it might be a silly idea. But this is my first Awk programming
task. :)

Re: Storing a Linux shell command into an AWK variable

<ursp7n$19edn$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1775&group=comp.lang.awk#1775

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Fri, 1 Mar 2024 15:37:41 +0100
Organization: A noiseless patient Spider
Lines: 79
Message-ID: <ursp7n$19edn$1@dont-email.me>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
<urqa8j$mfmd$1@toylet.eternal-september.org> <urqehb$nfru$1@dont-email.me>
<ursk3h$18a2o$1@toylet.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 14:37:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="573b6f3271b5f86b0906bbb1ccc77221";
logging-data="1358263"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sj0hs7UJyoUxs4w3q6Ygs"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:xIGJepy1K8zK0IOew4UvloYxeag=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <ursk3h$18a2o$1@toylet.eternal-september.org>
 by: Janis Papanagnou - Fri, 1 Mar 2024 14:37 UTC

On 01.03.2024 14:10, Mr. Man-wai Chang wrote:
> On 1/3/2024 1:22 am, Janis Papanagnou wrote:
>> On 29.02.2024 17:09, Mr. Man-wai Chang wrote:
>>>> On Thu, 29 Feb 2024 20:18:56 +0800, "Mr. Man-wai Chang"
>>>> <toylet.toylet@gmail.com> wrote:
>>>>
>>>>> How could I store the following BASH command into an Awk variable?
>>>>>
>>>>> **** begin *****
>>>>> site_survey 2>&1 | \
>>>>> sed -e 's/^./{/' \
>>>>> -e 's/\] SSID\[/\} SSID\{/' \
>>>>> -e 's/\] channel\[/} channel{/' \
>>>>> -e 's/\] enc\[/} enc{/' \
>>>>> -e 's/.$/\}/'
>>>>> **** end *****
>> [...]
>>>
>>> Thanks!
>>>
>>> Because of the call to sed within the Awk vaariable, need to escape:
>>>
>>> 1. "]" to "\\]"
>>> 2. "[" to "\\["
>>> 3. "'" to "'\''"
>>>
>>> Absolutely horrifying. :)
>>>
>>> This is what I end up with:
>>>
>>> cmd="site_survey 2>&1 | \
>>> sed -e '\''s/^./{/'\'' \
>>> -e '\''s/\\] SSID\\[/\} SSID\{/'\'' \
>>> -e '\''s/\\] channel\\[/} channel{/'\'' \
>>> -e '\''s/\\] enc\\[/} enc{/'\'' \
>>> -e '\''s/.$/\}/'\'' ";
>>>
>>
>> Whenever I see this sort of question and the attempted "solution"
>> I'm tempted to ask whether your approach might be not be the best;
>> there's quite some indications. - Mind to elaborate on the task
>> (not technically, but as seen from a higher perspective)?
>
> The site_survey command vomits lines:
>
> [ 8] SSID[ [HOME]] BSSID[04:9F:xx:xx:xx:xx] channel[ 6]
> frequency[2437] numsta[1] rssi[-63] noise[-75] beacon[98] cap[1411]
> dtim[0] rate[450] enc[Group-AES-CCMP CCMP PSK2 ]
>
> Just wanna change all field delimiters, which are square brackets, to
> curly braces within an Awk program loop.
>
> I agree it might be a silly idea. But this is my first Awk programming
> task. :)

Not necessarily. But I want to explain the reason for my question.

Composing a shell command in Awk typically has two (but maybe more)
application cases; one is to construct the shell commands to invoke
them from within Awk with the system() function, or to print them
so that you can store them in a file of pipe them into a shell for
direct execution.

It _might_ be better to do these commands in shell instead. (But I
still have not enough information to suggest the best approach.)

You noticed that substitutions with Awk might get nasty if escapes
are necessary for many characters. You may want to reduce the
number of characters to escape by changing the regular expression
that your Sed is using; it can be simplified (by 'or'ing the three
keywords, and likely by also incorporating the last sed expression.

An option might also be to not use Sed here but have an Awk do the
substitutions. The escaping complexity can also be reduced if you
put the Sed (or Awk) substitution commands into a file so that you
don't need to do all that ' quoting and escaping.

Janis

Re: Storing a Linux shell command into an AWK variable

<ursv6a$1an2m$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1778&group=comp.lang.awk#1778

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Sat, 2 Mar 2024 00:19:21 +0800
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ursv6a$1an2m$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
<urqa8j$mfmd$1@toylet.eternal-september.org> <urqehb$nfru$1@dont-email.me>
<ursk3h$18a2o$1@toylet.eternal-september.org> <ursp7n$19edn$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 16:19:22 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="a5dfc74f3d92357c9c3e5d43cc47f31b";
logging-data="1399894"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18elL6g2vw5C7sg54t00QB5"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:WhKHSCJXTL/FwXzmaUOXrn/tGzk=
In-Reply-To: <ursp7n$19edn$1@dont-email.me>
Content-Language: en-US
 by: Mr. Man-wai Chang - Fri, 1 Mar 2024 16:19 UTC

On 1/3/2024 10:37 pm, Janis Papanagnou wrote:
>
> Composing a shell command in Awk typically has two (but maybe more)
> application cases; one is to construct the shell commands to invoke
> them from within Awk with the system() function, or to print them
> so that you can store them in a file of pipe them into a shell for
> direct execution.
>
> It _might_ be better to do these commands in shell instead. (But I
> still have not enough information to suggest the best approach.)
>
> You noticed that substitutions with Awk might get nasty if escapes
> are necessary for many characters. You may want to reduce the
> number of characters to escape by changing the regular expression
> that your Sed is using; it can be simplified (by 'or'ing the three
> keywords, and likely by also incorporating the last sed expression.

Because the shell command is to be looped inside the Awk script with
data accumulation and calculation!

> An option might also be to not use Sed here but have an Awk do the
> substitutions. The escaping complexity can also be reduced if you
> put the Sed (or Awk) substitution commands into a file so that you
> don't need to do all that ' quoting and escaping.

That will involve more programming and testing. But I agree with yuo.

Re: Storing a Linux shell command into an AWK variable

<urt0cp$1aucd$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1782&group=comp.lang.awk#1782

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Sat, 2 Mar 2024 00:39:52 +0800
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <urt0cp$1aucd$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
<urqa8j$mfmd$1@toylet.eternal-september.org> <urqehb$nfru$1@dont-email.me>
<ursk3h$18a2o$1@toylet.eternal-september.org> <ursp7n$19edn$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 16:39:53 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="a5dfc74f3d92357c9c3e5d43cc47f31b";
logging-data="1407373"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DJcaAEcbUI3frDIl5co1S"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:qPClRw4nt4DU2jXhzAxAV4dgb4c=
In-Reply-To: <ursp7n$19edn$1@dont-email.me>
Content-Language: en-US
 by: Mr. Man-wai Chang - Fri, 1 Mar 2024 16:39 UTC

On 1/3/2024 10:37 pm, Janis Papanagnou wrote:
>
> An option might also be to not use Sed here but have an Awk do the
> substitutions. The escaping complexity can also be reduced if you
> put the Sed (or Awk) substitution commands into a file so that you
> don't need to do all that ' quoting and escaping.

That's an intermediate step I took before I figured out the complicated
character escaping stuffs. I did put the command into a Ash shell script
first. ;)

For your curiosity, here is the script I am trying to enhance:

DD-WRT :: View topic - Wireless scanner for linux
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=34924

It's written by someone else over 10 years ago, and I have no control
over the site_survey command. It will be easier if the command could
allow users to specify the output format and delimiters via optional
command-line options.

Re: Storing a Linux shell command into an AWK variable

<urt3a9$1bmie$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1784&group=comp.lang.awk#1784

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Fri, 1 Mar 2024 18:29:44 +0100
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <urt3a9$1bmie$1@dont-email.me>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
<urqa8j$mfmd$1@toylet.eternal-september.org> <urqehb$nfru$1@dont-email.me>
<ursk3h$18a2o$1@toylet.eternal-september.org> <ursp7n$19edn$1@dont-email.me>
<ursv6a$1an2m$1@toylet.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 17:29:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d63b5913b208007a66e59d1f1c95c79a";
logging-data="1432142"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6gcwiFHcoBHT3r+c+kAW+"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:QKfJZZhFVZJUTcu5DPvgjWK5GE8=
In-Reply-To: <ursv6a$1an2m$1@toylet.eternal-september.org>
 by: Janis Papanagnou - Fri, 1 Mar 2024 17:29 UTC

On 01.03.2024 17:19, Mr. Man-wai Chang wrote:
> On 1/3/2024 10:37 pm, Janis Papanagnou wrote:
>>
>> Composing a shell command in Awk typically has two (but maybe more)
>> application cases; one is to construct the shell commands to invoke
>> them from within Awk with the system() function, or to print them
>> so that you can store them in a file of pipe them into a shell for
>> direct execution.
>>
>> It _might_ be better to do these commands in shell instead. (But I
>> still have not enough information to suggest the best approach.)
>>
>> [...]
>
> Because the shell command is to be looped inside the Awk script with
> data accumulation and calculation!

Sorry, that description is unclear to me.
(Yet it still sounds to me as you've not chosen
the appropriate separation between Shell and Awk.)

Janis

Re: Storing a Linux shell command into an AWK variable

<urut1c$1qhfm$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1785&group=comp.lang.awk#1785

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Sat, 2 Mar 2024 17:54:51 +0800
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <urut1c$1qhfm$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ui41ui58831l3shpsriof414kk7g7dmh1n@dim53.demon.nl>
<urqa8j$mfmd$1@toylet.eternal-september.org> <urqehb$nfru$1@dont-email.me>
<ursk3h$18a2o$1@toylet.eternal-september.org> <ursp7n$19edn$1@dont-email.me>
<ursv6a$1an2m$1@toylet.eternal-september.org> <urt3a9$1bmie$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Mar 2024 09:54:52 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="9b2379fc508853fff19e5489cc0d514c";
logging-data="1918454"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ug8eiM2WV5j0OQrE9fquC"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:pCkZzc0T1B2cmn4EEdEqT0sQkS0=
In-Reply-To: <urt3a9$1bmie$1@dont-email.me>
Content-Language: en-US
 by: Mr. Man-wai Chang - Sat, 2 Mar 2024 09:54 UTC

On 2/3/2024 1:29 am, Janis Papanagnou wrote:
>
> Sorry, that description is unclear to me.
> (Yet it still sounds to me as you've not chosen
> the appropriate separation between Shell and Awk.)

Back to the site_survey example.

You want to count bssid after each call to site_survey, how could you
not loop the output of site_survey inside Awk? Unless you have a way to
save the counts outside Awk?

Re: Storing a Linux shell command into an AWK variable

<urv3cg$20td8$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1786&group=comp.lang.awk#1786

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Sat, 2 Mar 2024 11:43:12 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <urv3cg$20td8$1@news.xmission.com>
References: <urpsnh$gu7u$1@toylet.eternal-september.org> <ursv6a$1an2m$1@toylet.eternal-september.org> <urt3a9$1bmie$1@dont-email.me> <urut1c$1qhfm$1@toylet.eternal-september.org>
Injection-Date: Sat, 2 Mar 2024 11:43:12 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2127272"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sat, 2 Mar 2024 11:43 UTC

In article <urut1c$1qhfm$1@toylet.eternal-september.org>,
Mr. Man-wai Chang <toylet.toylet@gmail.com> wrote:
>On 2/3/2024 1:29 am, Janis Papanagnou wrote:
>>
>> Sorry, that description is unclear to me.
>> (Yet it still sounds to me as you've not chosen
>> the appropriate separation between Shell and Awk.)
>
>Back to the site_survey example.
>
>You want to count bssid after each call to site_survey, how could you
>not loop the output of site_survey inside Awk? Unless you have a way to
>save the counts outside Awk?
>

Just to get some sort of baseline example, is there any reason you can't do
it like this:

$ site_survey | awk '...'

where the awk program (the "..." above) does whatever manipulations you
need; i.e., all the substitutions you had previously been doing in "sed".

Note: The real problem here is that none of the people who are trying to
help you (*) have any real idea what your actual program looks like.

(*) A group I now seem to have added myself to.

--
People who want to share their religious views with you
almost never want you to share yours with them. -- Dave Barry

Re: Storing a Linux shell command into an AWK variable

<us1iho$2ek82$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1787&group=comp.lang.awk#1787

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED.110235006069.ctinets.com!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Sun, 3 Mar 2024 18:14:15 +0800
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <us1iho$2ek82$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ursv6a$1an2m$1@toylet.eternal-september.org> <urt3a9$1bmie$1@dont-email.me>
<urut1c$1qhfm$1@toylet.eternal-september.org>
<urv3cg$20td8$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Mar 2024 10:14:16 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="110235006069.ctinets.com:110.235.6.69";
logging-data="2576642"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: Mozilla Thunderbird
In-Reply-To: <urv3cg$20td8$1@news.xmission.com>
Content-Language: en-US
 by: Mr. Man-wai Chang - Sun, 3 Mar 2024 10:14 UTC

On 2/3/2024 7:43 pm, Kenny McCormack wrote:
> In article <urut1c$1qhfm$1@toylet.eternal-september.org>,
> Mr. Man-wai Chang <toylet.toylet@gmail.com> wrote:
>>
>> Back to the site_survey example.
>>
>> You want to count bssid after each call to site_survey, how could you
>> not loop the output of site_survey inside Awk? Unless you have a way to
>> save the counts outside Awk?
>
> Just to get some sort of baseline example, is there any reason you can't do
> it like this:
>
> $ site_survey | awk '...'
>
> where the awk program (the "..." above) does whatever manipulations you
> need; i.e., all the substitutions you had previously been doing in "sed".

I want to count the bssid after each call to site_survey, accumulative!
To do that outside of Awk '...', you need a place to store the counts
from last call to site_survey.
# # something like this:
# n[bssid]=0
for (;;) {
count_bssid(site_survey, n)
endfor
print n[bssid]

Re: Storing a Linux shell command into an AWK variable

<us1ijr$2ek82$2@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1788&group=comp.lang.awk#1788

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED.110235006069.ctinets.com!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Sun, 3 Mar 2024 18:15:22 +0800
Organization: A noiseless patient Spider
Message-ID: <us1ijr$2ek82$2@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ursv6a$1an2m$1@toylet.eternal-september.org> <urt3a9$1bmie$1@dont-email.me>
<urut1c$1qhfm$1@toylet.eternal-september.org>
<urv3cg$20td8$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Mar 2024 10:15:24 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="110235006069.ctinets.com:110.235.6.69";
logging-data="2576642"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <urv3cg$20td8$1@news.xmission.com>
 by: Mr. Man-wai Chang - Sun, 3 Mar 2024 10:15 UTC

On 2/3/2024 7:43 pm, Kenny McCormack wrote:
> Note: The real problem here is that none of the people who are trying to
> help you (*) have any real idea what your actual program looks like.
>
> (*) A group I now seem to have added myself to.

I just wanna find out whether there is an easier or smarter solution
using Awk ONLY. Pure Awk programming. :)

Re: Storing a Linux shell command into an AWK variable

<us24k3$2i895$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1790&group=comp.lang.awk#1790

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED.2001:a61:2633:2b01:88ab:a6ed:a355:85be!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Sun, 3 Mar 2024 16:22:41 +0100
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <us24k3$2i895$1@dont-email.me>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ursv6a$1an2m$1@toylet.eternal-september.org> <urt3a9$1bmie$1@dont-email.me>
<urut1c$1qhfm$1@toylet.eternal-september.org>
<urv3cg$20td8$1@news.xmission.com>
<us1iho$2ek82$1@toylet.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Mar 2024 15:22:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2001:a61:2633:2b01:88ab:a6ed:a355:85be";
logging-data="2695461"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <us1iho$2ek82$1@toylet.eternal-september.org>
 by: Janis Papanagnou - Sun, 3 Mar 2024 15:22 UTC

On 03.03.2024 11:14, Mr. Man-wai Chang wrote:
> On 2/3/2024 7:43 pm, Kenny McCormack wrote:
>> In article <urut1c$1qhfm$1@toylet.eternal-september.org>,
>> Mr. Man-wai Chang <toylet.toylet@gmail.com> wrote:
>>>
>>> Back to the site_survey example.
>>>
>>> You want to count bssid after each call to site_survey, how could you
>>> not loop the output of site_survey inside Awk? Unless you have a way to
>>> save the counts outside Awk?
>>
>> Just to get some sort of baseline example, is there any reason you
>> can't do
>> it like this:
>>
>> $ site_survey | awk '...'
>>
>> where the awk program (the "..." above) does whatever manipulations you
>> need; i.e., all the substitutions you had previously been doing in "sed".
>
> I want to count the bssid after each call to site_survey, accumulative!

I don't see how the previous construction of a sed command helps here.
It's still fuzzy to me what you want, so below I can give you some
informal hints and once you've chosen which way you want to go you
can come back with more specific questions.

One general way of doing such things is (informally written)

data_source | awk '{ x=extract-data() ; c+=x } END { print c }'

where extract-data is some regular expression match of the data format
you are parsing, and
where data-source may be a single call of a program like 'site_survey',
or a shell-loop of program calls like

while some-condition
do
site_survey "${parameters}"
done | awk '...'

> To do that outside of Awk '...', you need a place to store the counts
> from last call to site_survey.

This is also possible. As in

c=0
while some-condition
do
c=$(( c + $(site_survey "${parameters}" | extract-data) ))
done
echo $c

where extract-data is some tool (sed, awk, etc.) to get the data from
the site_survey command.

> #
> # something like this:
> #
> n[bssid]=0
> for (;;) {
> count_bssid(site_survey, n)
> endfor
> print n[bssid]

Janis

Re: Storing a Linux shell command into an AWK variable

<87cysbkzey.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1792&group=comp.lang.awk#1792

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Sun, 03 Mar 2024 17:17:41 +0000
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <87cysbkzey.fsf@bsb.me.uk>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ursv6a$1an2m$1@toylet.eternal-september.org>
<urt3a9$1bmie$1@dont-email.me>
<urut1c$1qhfm$1@toylet.eternal-september.org>
<urv3cg$20td8$1@news.xmission.com>
<us1iho$2ek82$1@toylet.eternal-september.org>
<us24k3$2i895$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1c872d7752bdf1782916c4053c614660";
logging-data="2740118"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Yg+kSUHtbysuEoLtER5WcOxPzPYV8/Ik="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:KYMIUCZ1GLC/6bceFLS0N1wLcuI=
sha1:J77HpuViLZbPDQK/e6ExlYSUTnI=
X-BSB-Auth: 1.26766858d9027e387f29.20240303171741GMT.87cysbkzey.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 3 Mar 2024 17:17 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

> On 03.03.2024 11:14, Mr. Man-wai Chang wrote:
>> On 2/3/2024 7:43 pm, Kenny McCormack wrote:
>>> In article <urut1c$1qhfm$1@toylet.eternal-september.org>,
>>> Mr. Man-wai Chang <toylet.toylet@gmail.com> wrote:
>>>>
>>>> Back to the site_survey example.
>>>>
>>>> You want to count bssid after each call to site_survey, how could you
>>>> not loop the output of site_survey inside Awk? Unless you have a way to
>>>> save the counts outside Awk?
>>>
>>> Just to get some sort of baseline example, is there any reason you
>>> can't do
>>> it like this:
>>>
>>> $ site_survey | awk '...'
>>>
>>> where the awk program (the "..." above) does whatever manipulations you
>>> need; i.e., all the substitutions you had previously been doing in "sed".
>>
>> I want to count the bssid after each call to site_survey, accumulative!
>
> I don't see how the previous construction of a sed command helps here.
> It's still fuzzy to me what you want, so below I can give you some
> informal hints and once you've chosen which way you want to go you
> can come back with more specific questions.
>
>
> One general way of doing such things is (informally written)
>
> data_source | awk '{ x=extract-data() ; c+=x } END { print c }'

As you say it's not very clear what is needed, but I think the key point
is that the data must be accumulated. The basic pattern is probably
then more like

data_source | awk \
'BEGIN { d = read_saved_data(); } { x=extract-data() ; d[something] += x }
END { write_data(d); }'

though there may be data output as well. In fact it's possible that the
simplest way to store the accumulating data is to output it and use tee:

data_source | awk \
'BEGIN { d = read_saved_data(); } { x=extract-data() ; d[something] += x }
END { print lots of stats...; }' | tee saved_data

--
Ben.

Re: Storing a Linux shell command into an AWK variable

<us4hui$35jha$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1794&group=comp.lang.awk#1794

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Mon, 4 Mar 2024 21:22:25 +0800
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <us4hui$35jha$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ursv6a$1an2m$1@toylet.eternal-september.org> <urt3a9$1bmie$1@dont-email.me>
<urut1c$1qhfm$1@toylet.eternal-september.org>
<urv3cg$20td8$1@news.xmission.com>
<us1iho$2ek82$1@toylet.eternal-september.org> <us24k3$2i895$1@dont-email.me>
<87cysbkzey.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Mar 2024 13:22:26 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="1dc1657cfb18c126bb5f45a89d37376d";
logging-data="3329578"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UVpezw96hXcHyGCnVu5Ul"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:g/vKcYnL2StHE0q1GnikOUuGurE=
Content-Language: en-US
In-Reply-To: <87cysbkzey.fsf@bsb.me.uk>
 by: Mr. Man-wai Chang - Mon, 4 Mar 2024 13:22 UTC

On 4/3/2024 1:17 am, Ben Bacarisse wrote:
> As you say it's not very clear what is needed, but I think the key point
> is that the data must be accumulated. The basic pattern is probably
> then more like
>
> data_source | awk \
> 'BEGIN { d = read_saved_data(); } { x=extract-data() ; d[something] += x }
> END { write_data(d); }'
>
> though there may be data output as well. In fact it's possible that the
> simplest way to store the accumulating data is to output it and use tee:
>
> data_source | awk \
> 'BEGIN { d = read_saved_data(); } { x=extract-data() ;
d[something] += x }
> END { print lots of stats...; }' | tee saved_data
>

That's exactly what I was trying to do. How do you store and restore the
array of counts[bssid]? Flatten the array into Bash variables?

I think it's not too bad to do everything within the Awk script, given
Awk's capabilties.

Re: Storing a Linux shell command into an AWK variable

<874jdmklwm.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1797&group=comp.lang.awk#1797

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Mon, 04 Mar 2024 16:21:45 +0000
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <874jdmklwm.fsf@bsb.me.uk>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<ursv6a$1an2m$1@toylet.eternal-september.org>
<urt3a9$1bmie$1@dont-email.me>
<urut1c$1qhfm$1@toylet.eternal-september.org>
<urv3cg$20td8$1@news.xmission.com>
<us1iho$2ek82$1@toylet.eternal-september.org>
<us24k3$2i895$1@dont-email.me> <87cysbkzey.fsf@bsb.me.uk>
<us4hui$35jha$1@toylet.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="55b12cd97f483f0b07ab5f700525753a";
logging-data="3408533"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vKKPJcp/JT653bhkWuzu56FcR33/zSQY="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:X5tRrM8bTV4N10s54hj4RBsnztM=
sha1:cxndHOyHFC/lnLVMpbJxZECltrM=
X-BSB-Auth: 1.9bc17ec1b421d36f2331.20240304162145GMT.874jdmklwm.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 4 Mar 2024 16:21 UTC

"Mr. Man-wai Chang" <toylet.toylet@gmail.com> writes:

> On 4/3/2024 1:17 am, Ben Bacarisse wrote:
>> As you say it's not very clear what is needed, but I think the key point
>> is that the data must be accumulated. The basic pattern is probably
>> then more like
>> data_source | awk \
>> 'BEGIN { d = read_saved_data(); } { x=extract-data() ; d[something] += x }
>> END { write_data(d); }'
>> though there may be data output as well. In fact it's possible that the
>> simplest way to store the accumulating data is to output it and use tee:
>>
>> data_source | awk \
>> 'BEGIN { d = read_saved_data(); } { x=extract-data() ; d[something] +=
> x }
>> END { print lots of stats...; }' | tee saved_data
>>
>
> That's exactly what I was trying to do. How do you store and restore the
> array of counts[bssid]? Flatten the array into Bash variables?

I would write it to a file. That's what I was trying to suggest with
the pseudo code.

> I think it's not too bad to do everything within the Awk script, given
> Awk's capabilties.

Yes, but in the old days (when I had to do this sort of stuff more
often) I would usually switch to Perl when I started to have to manage
files other than the standard input and standard output. But that's
because I knew both so the switch was simple.

--
Ben.

Re: Storing a Linux shell command into an AWK variable

<us9pit$e711$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1800&group=comp.lang.awk#1800

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Wed, 6 Mar 2024 07:03:25 -0600
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <us9pit$e711$1@dont-email.me>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 6 Mar 2024 13:03:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="43e16991614ffbac42df9b4db79ac92d";
logging-data="465953"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/v0MvcNZy+h9kvS4k/hA4E"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:3bJDI/rWVEVtq5LF4N4iP/UYza8=
X-Antivirus: Avast (VPS 240305-4, 3/5/2024), Outbound message
In-Reply-To: <urpsnh$gu7u$1@toylet.eternal-september.org>
Content-Language: en-US
X-Antivirus-Status: Clean
 by: Ed Morton - Wed, 6 Mar 2024 13:03 UTC

On 2/29/2024 6:18 AM, Mr. Man-wai Chang wrote:
> How could I store the following BASH command into an Awk variable?
>
> **** begin *****
> site_survey 2>&1 | \
> sed -e 's/^./{/' \
> -e 's/\] SSID\[/\} SSID\{/' \
> -e 's/\] channel\[/} channel{/' \
> -e 's/\] enc\[/} enc{/' \
> -e 's/.$/\}/'
> **** end *****

Do not do this. You wouldn't do it in shell (see
https://mywiki.wooledge.org/BashFAQ/050) and you definitely must not do
this in awk as that'll have all of the issues associated with storing
code in a shell variable PLUS additional issues of robustness and
efficiency related to spawning a subshell to call an external tool from awk.

Whatever it is you're trying to do, post a new question with a minimal
complete, verifiable example (see
https://stackoverflow.com/help/minimal-reproducible-example for what
that means) so we can help you do it the right way.

Ed.

Re: Storing a Linux shell command into an AWK variable

<usc4tk$10akp$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1801&group=comp.lang.awk#1801

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Thu, 7 Mar 2024 18:29:07 +0800
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <usc4tk$10akp$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<us9pit$e711$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Mar 2024 10:29:08 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="b0cff707f8ab6ee094f5abe004b22088";
logging-data="1059481"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1801nArCePIloJV+ZqjuVbD"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Ze4RrA/y3MGJLtJwARwv5SQgA7g=
In-Reply-To: <us9pit$e711$1@dont-email.me>
Content-Language: en-US
 by: Mr. Man-wai Chang - Thu, 7 Mar 2024 10:29 UTC

On 6/3/2024 9:03 pm, Ed Morton wrote:
>
> Do not do this. You wouldn't do it in shell (see
> https://mywiki.wooledge.org/BashFAQ/050) and you definitely must not do
> this in awk as that'll have all of the issues associated with storing
> code in a shell variable PLUS additional issues of robustness and
> efficiency related to spawning a subshell to call an external tool from awk.

I undertsand the limitations of Awk. But I was wondering about how far I
could go. :)

> Whatever it is you're trying to do, post a new question with a minimal
> complete, verifiable example (see
> https://stackoverflow.com/help/minimal-reproducible-example for what
> that means) so we can help you do it the right way.

Already done so. My question in the end was more about escaping
special/reserved symbols.

Re: Storing a Linux shell command into an AWK variable

<uscabc$274mq$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1802&group=comp.lang.awk#1802

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Thu, 7 Mar 2024 12:01:49 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uscabc$274mq$1@news.xmission.com>
References: <urpsnh$gu7u$1@toylet.eternal-september.org> <us9pit$e711$1@dont-email.me> <usc4tk$10akp$1@toylet.eternal-september.org>
Injection-Date: Thu, 7 Mar 2024 12:01:49 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2331354"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 7 Mar 2024 12:01 UTC

In article <usc4tk$10akp$1@toylet.eternal-september.org>,
Mr. Man-wai Chang <toylet.toylet@gmail.com> wrote:
....
>Already done so. My question in the end was more about escaping
>special/reserved symbols.

Well, not really.

At this point, I still don't think anyone else reading/posting to this
thread has any real idea what you are actually trying to do.

Now, it is certainly your right not to tell us, and we don't really have
any right to insist that you do, but it does limit the amount of help we
can provide. FWIW (and that might not be much), I think most of us are
having a reaction of "Whatever it is you're trying to do, this is not the
right way to do it".

Now, to be fair, you did give a slight hint as to what this was really
about, somewhere upthread, where you indicated that this was a program that
you got from someone/somewhere on the net and you just needed to modify it
slightly to make it do what you wanted. In that case, an "I just need help
with one simple thing" type answer might actually be appropriate. Again
FWIW, I think most of the help-givers on this thread have assumed that this
was your own program and that you are developing it from scratch.

--
I love the poorly educated.

Re: Storing a Linux shell command into an AWK variable

<uscgmu$12smn$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1803&group=comp.lang.awk#1803

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Thu, 7 Mar 2024 14:50:21 +0100
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <uscgmu$12smn$1@dont-email.me>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<us9pit$e711$1@dont-email.me> <usc4tk$10akp$1@toylet.eternal-september.org>
<uscabc$274mq$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Mar 2024 13:50:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0d87425d43dfe176d38af3ee0429ae5f";
logging-data="1143511"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QoioKDB+1423+Xvqe78BA"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:0Atqg/QJVzbRh1THKv6NMo/C/7U=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <uscabc$274mq$1@news.xmission.com>
 by: Janis Papanagnou - Thu, 7 Mar 2024 13:50 UTC

On 07.03.2024 13:01, Kenny McCormack wrote:
> In article <usc4tk$10akp$1@toylet.eternal-september.org>,
> Mr. Man-wai Chang <toylet.toylet@gmail.com> wrote:
> ...
>> Already done so. My question in the end was more about escaping
>> special/reserved symbols.
>
> Well, not really.
>
> At this point, I still don't think anyone else reading/posting to this
> thread has any real idea what you are actually trying to do.
>
> Now, it is certainly your right not to tell us, and we don't really have
> any right to insist that you do, but it does limit the amount of help we
> can provide. FWIW (and that might not be much), I think most of us are
> having a reaction of "Whatever it is you're trying to do, this is not the
> right way to do it".
>
> Now, to be fair, you did give a slight hint as to what this was really
> about, somewhere upthread, where you indicated that this was a program that
> you got from someone/somewhere on the net and you just needed to modify it
> slightly to make it do what you wanted. In that case, an "I just need help
> with one simple thing" type answer might actually be appropriate. Again
> FWIW, I think most of the help-givers on this thread have assumed that this
> was your own program and that you are developing it from scratch.

I second what you wrote. Given that it's another person's tool
it might be advantageous to rewrite that tool if the original
code already had chosen the wrong partitioning between shell
and awk. The "one simple thing" might turn out to not be that
simple if the wrong approach had been chosen. But, yes, that's
the OP's decision.

Janis

Re: Storing a Linux shell command into an AWK variable

<uschpq$13549$1@toylet.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1804&group=comp.lang.awk#1804

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!toylet.eternal-september.org!.POSTED!not-for-mail
From: toylet.toylet@gmail.com (Mr. Man-wai Chang)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Thu, 7 Mar 2024 22:08:58 +0800
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <uschpq$13549$1@toylet.eternal-september.org>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<us9pit$e711$1@dont-email.me> <usc4tk$10akp$1@toylet.eternal-september.org>
<uscabc$274mq$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Mar 2024 14:08:58 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="b0cff707f8ab6ee094f5abe004b22088";
logging-data="1152137"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19TVv3N9Fq2dh40juRmxRXJ"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:UpJpP49y8FxvKhXjdpfma7h3ckE=
In-Reply-To: <uscabc$274mq$1@news.xmission.com>
Content-Language: en-US
 by: Mr. Man-wai Chang - Thu, 7 Mar 2024 14:08 UTC

On 7/3/2024 8:01 pm, Kenny McCormack wrote:
> Now, it is certainly your right not to tell us, and we don't really have
> any right to insist that you do, but it does limit the amount of help we
> can provide. FWIW (and that might not be much), I think most of us are
> having a reaction of "Whatever it is you're trying to do, this is not the
> right way to do it".
>
> Now, to be fair, you did give a slight hint as to what this was really
> about, somewhere upthread, where you indicated that this was a program that
> you got from someone/somewhere on the net and you just needed to modify it
> slightly to make it do what you wanted. In that case, an "I just need help
> with one simple thing" type answer might actually be appropriate. Again
> FWIW, I think most of the help-givers on this thread have assumed that this
> was your own program and that you are developing it from scratch.

I understand and thank all the suggestions here.

Re: Storing a Linux shell command into an AWK variable

<usf5f2$1nj3v$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1810&group=comp.lang.awk#1810

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Re: Storing a Linux shell command into an AWK variable
Date: Fri, 8 Mar 2024 07:56:51 -0600
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <usf5f2$1nj3v$1@dont-email.me>
References: <urpsnh$gu7u$1@toylet.eternal-september.org>
<us9pit$e711$1@dont-email.me> <usc4tk$10akp$1@toylet.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Mar 2024 13:56:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d807f9e1f2027660b0abd20856aab4e5";
logging-data="1821823"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//r0u237BjiCNBYDUH9Csr"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:1ANMNuZ5ZRgPo3IQ+tRu5DfZVek=
X-Antivirus: Avast (VPS 240308-0, 3/7/2024), Outbound message
In-Reply-To: <usc4tk$10akp$1@toylet.eternal-september.org>
X-Antivirus-Status: Clean
Content-Language: en-US
 by: Ed Morton - Fri, 8 Mar 2024 13:56 UTC

On 3/7/2024 4:29 AM, Mr. Man-wai Chang wrote:
> On 6/3/2024 9:03 pm, Ed Morton wrote:
>>
>> Do not do this. You wouldn't do it in shell (see
>> https://mywiki.wooledge.org/BashFAQ/050) and you definitely must not do
>> this in awk as that'll have all of the issues associated with storing
>> code in a shell variable PLUS additional issues of robustness and
>> efficiency related to spawning a subshell to call an external tool
>> from awk.
>
> I undertsand the limitations of Awk. But I was wondering about how far I
> could go. :)

It's not a limitation of awk any more than trying to dig a ditch with a
toothbrush would uncover a limitation of the toothbrush, it's just a
matter of using the right tool for the job and awk is not a tool to
sequence calls to other tools - that's what a shell is for.

>
>> Whatever it is you're trying to do, post a new question with a minimal
>> complete, verifiable example (see
>> https://stackoverflow.com/help/minimal-reproducible-example for what
>> that means) so we can help you do it the right way.
>
> Already done so. My question in the end was more about escaping
> special/reserved symbols.

No, there is no MCVE anywhere in this thread. Any help you think you're
getting is based on guesses and assumptions and any implementation
suggestions you got would be similar to getting instructions if you
asked how to load a gun while it's pointed at your foot rather than just
being told "don't do that" so treat everything with a large pinch of
salt as we simply cannot know what it is you're really trying to do
given what you've shown us so far.

Ed.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor