Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Two percent of zero is almost nothing.


devel / comp.lang.awk / Unique In Column

SubjectAuthor
* Unique In ColumnMike Sanders
`* Re: Unique In ColumnMike Sanders
 `* Re: Unique In ColumnEd Morton
  `- Re: Unique In ColumnMike Sanders

1
Unique In Column

<ufdqcc$2qvn1$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkchop@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.awk
Subject: Unique In Column
Date: Mon, 2 Oct 2023 07:10:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <ufdqcc$2qvn1$1@dont-email.me>
Injection-Date: Mon, 2 Oct 2023 07:10:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b80093a998c08ec5e7b71710a7b0258d";
logging-data="2981601"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rMjoM0Vf3JtMvi/fkxSDO"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:+HoxwylRoYoRokw/Q2knAm55kKw=
 by: Mike Sanders - Mon, 2 Oct 2023 07:10 UTC

# verifies an item is unique to the 2nd column
# # example file.csv...
# # name, alias
# # john, kiwi
# suzi, apple
# suzi, orange

BEGIN { FS = ",[ \t]*|[ \t]+" }

{ Field2Values[tolower($2)] = 1 }

END { if (uniqueItem("apple", FILENAME) != 0) exit 1 }

function uniqueItem(field2, file) {

lowerField2 = tolower(field2)

if(lowerField2 in Field2Values) {
print "Error: '" field2 "' was found in 2nd column of " file
return 1
} else print "Item: '" field2 "' is unique to 2nd column of " file

return 0
}

# eof

--
:wq
Mike Sanders

Re: Unique In Column

<ufdruv$2r8sb$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkchop@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.awk
Subject: Re: Unique In Column
Date: Mon, 2 Oct 2023 07:37:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <ufdruv$2r8sb$1@dont-email.me>
References: <ufdqcc$2qvn1$1@dont-email.me>
Injection-Date: Mon, 2 Oct 2023 07:37:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b80093a998c08ec5e7b71710a7b0258d";
logging-data="2990987"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bJCY6ZxLO3GPTyelnkphQ"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:/29h3xUgLYvKEJ30sVaRJIQ33PM=
 by: Mike Sanders - Mon, 2 Oct 2023 07:37 UTC

Mike Sanders <porkchop@invalid.foo> wrote:

> # verifies an item is unique to the 2nd column

quick update, why hard-code a field number anyhow?

# verifies an item is unique to a give column
# # example file.csv...
# # name, alias
# # john, kiwi
# suzi, apple
# suzi, orange

BEGIN { FS = ",[ \t]*|[ \t]+"; COL = 2 }

{ FieldValues[tolower($COL)] = 1 }

END { if (uniqueItem(COL, "apple", FILENAME) != 0) exit 1 }

function uniqueItem(col, field, file) {

lowerField = tolower(field)

if(lowerField in FieldValues) {
print "Error: '" field "' was found in column " col " of " file
return 1
} else print "Item: '" field "' is unique to column " col " of " file

return 0
}

# eof

--
:wq
Mike Sanders

Re: Unique In Column

<ui8c75$1p6b$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Re: Unique In Column
Date: Sun, 5 Nov 2023 09:26:30 -0600
Organization: A noiseless patient Spider
Lines: 123
Message-ID: <ui8c75$1p6b$1@dont-email.me>
References: <ufdqcc$2qvn1$1@dont-email.me> <ufdruv$2r8sb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 5 Nov 2023 15:26:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="499fbea221ac1834cc2b299cfde571ca";
logging-data="58571"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cLQrNx/IRVcyoYFhzLlMl"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:LZHvVoooj0lB96refEjwJKzYv/8=
X-Antivirus: Avast (VPS 231105-0, 11/4/2023), Outbound message
In-Reply-To: <ufdruv$2r8sb$1@dont-email.me>
Content-Language: en-US
X-Antivirus-Status: Clean
 by: Ed Morton - Sun, 5 Nov 2023 15:26 UTC

On 10/2/2023 2:37 AM, Mike Sanders wrote:
> Mike Sanders <porkchop@invalid.foo> wrote:
>
>> # verifies an item is unique to the 2nd column
>
> quick update, why hard-code a field number anyhow?
>
> # verifies an item is unique to a give column
> #
> # example file.csv...
> #
> # name, alias
> #
> # john, kiwi
> # suzi, apple
> # suzi, orange
>
> BEGIN { FS = ",[ \t]*|[ \t]+"; COL = 2 }
>
> { FieldValues[tolower($COL)] = 1 }
>
> END { if (uniqueItem(COL, "apple", FILENAME) != 0) exit 1 }
>
> function uniqueItem(col, field, file) {
>
> lowerField = tolower(field)
>
> if(lowerField in FieldValues) {
> print "Error: '" field "' was found in column " col " of " file
> return 1
> } else print "Item: '" field "' is unique to column " col " of " file
>
> return 0
> }
>
> # eof
>

That's checking whether or not a value exists, not whether or not it's
unique, and producing the wrong output. If we modify it to take a
variable fruit:

$ cat tst.awk
BEGIN { FS = ",[ \t]*|[ \t]+"; COL = 2 }

{ FieldValues[tolower($COL)] = 1 }

END { if (uniqueItem(COL, fruit, FILENAME) != 0) exit 1 }

function uniqueItem(col, field, file) {

lowerField = tolower(field)

if(lowerField in FieldValues) {
print "Error: '" field "' was found in column " col " of " file
return 1
} else print "Item: '" field "' is unique to column " col " of " file

return 0
}

and add a second "apple" in column 2 of your CSV:

$ cat file.csv
john, kiwi
suzi, apple
suzi, orange
gwen, apple

then we can run it as:

$ awk -v fruit='kiwi' -f tst.awk file.csv
Error: 'kiwi' was found in column 2 of file.csv
$ awk -v fruit='apple' -f tst.awk file.csv
Error: 'apple' was found in column 2 of file.csv
$ awk -v fruit='grape' -f tst.awk file.csv
Item: 'grape' is unique to column 2 of file.csv

and you can see it's reporting that "grape" is a unique value when it's
not actually present at all.

If we change the script to:

$ cat tst.awk
BEGIN { FS = ",[ \t]*|[ \t]+"; COL = 2 }

{ FieldValues[tolower($COL)]++ }

END { if (uniqueItem(COL, fruit, FILENAME) != 0) exit 1 }

function uniqueItem(col, field, file) {

lowerField = tolower(field)

if(lowerField in FieldValues) {
if (FieldValues[lowerField] == 1) {
print "Item: '" field "' is unique to column " col " of " file
}
else {
print "Error: '" field "' was found in column " col " of " file
return 1
}
}
else {
print "Error: '" field "' was not found in column " col " of " file
}

return 0
}

THEN it'll report unique "fruit" values correctly as well as reporting
which are present/absent:

$ awk -v fruit='kiwi' -f tst.awk file.csv
Item: 'kiwi' is unique to column 2 of file.csv
$ awk -v fruit='apple' -f tst.awk file.csv
Error: 'apple' was found in column 2 of file.csv
$ awk -v fruit='grape' -f tst.awk file.csv
Error: 'grape' was not found in column 2 of file.csv

Regards,

Ed.

Re: Unique In Column

<ui9lm9$barj$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkchop@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.awk
Subject: Re: Unique In Column
Date: Mon, 6 Nov 2023 03:14:17 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <ui9lm9$barj$1@dont-email.me>
References: <ufdqcc$2qvn1$1@dont-email.me> <ufdruv$2r8sb$1@dont-email.me> <ui8c75$1p6b$1@dont-email.me>
Injection-Date: Mon, 6 Nov 2023 03:14:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bea9002c59825590baf04d6c11b58fc5";
logging-data="371571"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19AjKRcADaQjLHjq7DejWuK"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:21UxcYEbcSp0TnM4i7l4EQifjrk=
 by: Mike Sanders - Mon, 6 Nov 2023 03:14 UTC

Ed Morton <mortonspam@gmail.com> wrote:

> [...]

Thanks Ed, must study your example & mull it over =)

--
:wq
Mike Sanders

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor