bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] gawk array problem


From: david kerns
Subject: Re: [bug-gawk] gawk array problem
Date: Wed, 6 Apr 2016 13:57:30 -0700

change:

/del/ && M[$2] { delete M[$2]; print "-- "$2 }

to

/del/ && ($2 in M) { delete M[$2]; print "-- "$2 }      

you were creating M["3"]=0, which is false


On Wed, Apr 6, 2016 at 12:01 PM, Ludek Bican <address@hidden> wrote:
Hi,

 there is some problem with arrays

Regards,

Ludek
email: address@hidden

---------------------------------------------

$ uname -a
Linux ub1 3.13.0-63-generic #103-Ubuntu SMP Fri Aug 14 21:42:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

$ awk --ver | head -1
GNU Awk 4.0.1

$ dpkg -l gawk | tail -2  | cut -c 1-60
+++-====================-==========================-====
ii  gawk                                                        1:4.0.1+dfsg-2.1ubuntu2                             amd6

----------------------------------------
$ cat 1.txt
add  1
add  2
del 3
del 1
---------------------------------------
$ awk '
  /add/ { M[$2]++; print "++ "$2 }
  /del/ && M[$2] { delete M[$2]; print "-- "$2 }       
  END { for (I in M) print "stay "I }                    
' 1.txt
--------------------------------------
==== output:
++ 1
++ 2
-- 1
stay 2
stay 3    # ???????





reply via email to

[Prev in Thread] Current Thread [Next in Thread]