[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] AWK fails deleting member from associative array.
From: |
Sebastian Kricner |
Subject: |
[bug-gawk] AWK fails deleting member from associative array. |
Date: |
Sat, 4 Jan 2014 04:58:27 +0100 |
Here is the snippet:
#acronyms.awk - Extract searched acronym
BEGIN {
}
FILENAME == "acronyms" {
split($0, field, "\t");
acronyms[field[1]] = field[2];
next;
}
/[A-Z]{2,}/ {
for(i=0;i<=NF;i++)
{
if($i in acronyms)
{
$i = acronyms[$i] " ("$i")";
delete acronyms[$i];
}
}
}
{
print $0
}
This snippet gets called via awk -f acronyms.awk acronyms test, where
acronyms and test have following contents:
acronyms:
BASIC Beginners All-Purpose Symbolic Instruction Code
CICS Customer Information Control System
COBOL Common Business Oriented Language
DBMS Data Base Management System
GIGO Garbage In Garbage Out
GIRL Generalized Information Retrieval Language
test:
BASIC is a nice programming language.
And BASIC also is widely used.
This script shall replace BASIC with the full name and only once.
So it shall delete acronyms[$i], this fails. But delete
acronyms["BASIC"] works...also replacing works, but it does it twice.
Is this issue known?
System: Debian Wheezy - GNU Awk 4.0.1
Regards
Sebastian Kricner
--
http://tuxwave.net -- the difference to think makes it real!
signature.asc
Description: PGP signature
- [bug-gawk] AWK fails deleting member from associative array.,
Sebastian Kricner <=