bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] asort, sorted_in


From: Vincent Fournier
Subject: [bug-gawk] asort, sorted_in
Date: Thu, 15 Aug 2013 18:40:27 +0200 (CEST)

bug > gawk does not accept a third argument for the comparison function.

gawk version : GNU Awk 3.1.6
windows : 64bits
error : fatal: 3 is invalid as number of arguments for asort

Bug : The alternative way (PROCINFO["sorted_in"] = "mysortfunction") is not taken into account.

see file attached.

# objective : sort in a numerical order by the first colum (out of 2 colums)

BEGIN    {
 OFS="\t"
PROCINFO["sorted_in"] = "cmp_val"
delete s
delete d
for (i=1;i<12;i++)
    s[i] = (i-8)**4 "\t" i
   
# n=asort(s,d, "cmp_val")    # <= fatal: 3 is invalid as number of arguments for asort
n=asort(s,d )   

print "==== orig ==="   
for (i=1;i<12;i++)
    print s[i]
print "==== asort ==="   
for (i=1;i<12;i++)
    print d[i]
print "==== PROCINFO=== "   
for(j in s)
    print  s[j]
   
}



function cmp_val(i1, v1, i2, v2)
{
split(v1,a1,"\t")
split(v2,a2,"\t")
x1 = a1[1]+0
x2 = a2[1]+0
return (x1 - x2)

}



Vincent Fournier
04 93 51 02 92 (soir/répondeur)
0678543032 (travail)
http://croqueurfou.canalblog.com/

Attachment: sort.gawk
Description: Binary data


reply via email to

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