'How can I get the list of indices an associative array has? [closed]

I have an associative array in awk, and I can iterate over the values of the array using (e.g.) for (v in ARRAY) ....

However I want to iterate over the indices (keys) of the array instead.

Unfortunately I did not find the function how to do that. (In Perl I'd use keys %hash for that)



Solution 1:[1]

I have an associative array in awk, and I can iterate over the values of the array using (e.g.) for (v in ARRAY) ....

As far I as know it will do iterate over keys, consider following example

awk 'BEGIN{arr["a"]=1;arr["b"]=2;arr["c"]=3}END{for(i in arr){print i}}'

output

a
b
c

(tested in gawk 4.2.1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daweo