Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Phasers locked on target, Captain.


devel / comp.lang.awk / Re: Breaking a table of record rows into an array

SubjectAuthor
* Re: Breaking a table of record rows into an arrayjeorge
`- Re: Breaking a table of record rows into an arrayMr. Man-wai Chang

1
Re: Breaking a table of record rows into an array

<ursu1v$1ac5f$1@dont-email.me>

  copy mid

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

  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: jeorge@invalid.invalid
Newsgroups: comp.lang.awk
Subject: Re: Breaking a table of record rows into an array
Date: Fri, 1 Mar 2024 15:59:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <ursu1v$1ac5f$1@dont-email.me>
Injection-Date: Fri, 1 Mar 2024 15:59:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aeb95f9765c54d4484b44df394461e51";
logging-data="1388719"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/X0oiiccPou1JrTh8qcDZy"
Cancel-Lock: sha1:pqTOQVISJVUKNW1T+qAhhZT3g6M=
 by: jeorge@invalid.invalid - Fri, 1 Mar 2024 15:59 UTC

> I am new to Awk programming.
>
> Given a text table with the following sample entry:
>
> [ 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 ]
>
> How do you use Awk to quickly & easily break it into:
>
> bssid="04:9F:xx:xx:xx:xx";
> ssid[bssid]="[HOME]";
> channel[bssid]="6";
> frequency[bssid]="2437";
> ....
> rate[bssid]="450;
> enc[bssid]="Group-AES-CCMP CCMP PSK2";

Found your issue interesting enough to attempt a solution:

#../sandbox/test.awk
BEGIN { FS="\\[[ []*" ; RS="]" }
{ sub("\n","")
for (i=1; i<=NF; i+=2) {
($i ~ /^$/) ? $i = "Station" : sub(/^ */,"\t",$i)
if ($(i+1) != "")
printf "%s[bssid] = %s\n", $i,$(i+1)
} }

$ nawk -f test.awk test.data
Station[bssid] = 8
SSID[bssid] = HOME
BSSID[bssid] = 04:9F:xx:xx:xx:xx
channel[bssid] = 6
frequency[bssid] = 2437
numsta[bssid] = 1
rssi[bssid] = -63
noise[bssid] = -75
beacon[bssid] = 98
cap[bssid] = 1411
dtim[bssid] = 0
rate[bssid] = 450
enc[bssid] = Group-AES-CCMP CCMP PSK2

Re: Breaking a table of record rows into an array

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

  copy mid

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

  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: Breaking a table of record rows into an array
Date: Sat, 2 Mar 2024 00:23:22 +0800
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <ursvdr$1an2m$2@toylet.eternal-september.org>
References: <ursu1v$1ac5f$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:23:23 -0000 (UTC)
Injection-Info: toylet.eternal-september.org; posting-host="a5dfc74f3d92357c9c3e5d43cc47f31b";
logging-data="1399894"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fpi9m9fs2cs8k5UHmsXm8"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:IuHBTc078+GnBk0mbEzzra09Lt0=
In-Reply-To: <ursu1v$1ac5f$1@dont-email.me>
Content-Language: en-US
 by: Mr. Man-wai Chang - Fri, 1 Mar 2024 16:23 UTC

On 1/3/2024 11:59 pm, jeorge@invalid.invalid wrote:
>> I am new to Awk programming.
>>
>> Given a text table with the following sample entry:
>>

Being new to Awk programming, I am amazed to learn that Awk can
automaticlaly use a string as an array index. There is also automatic
type-conversion. Very much like Visual Foxpro and other dBase dialects I
am more fluent with! :)

But all dBase dialects cannot directly use a string as an array index.
You can work around it using macro substitution, but it's not direct
solution like Awk array.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor