I'm trying to abuse asort()
(just because) to copy an array src
to array dest
, no problem there:
$ awk 'BEGIN {
split("first;second;third",src,";") # make src array for testing
asort(src, dest, "@ind_num_asc") # copy array to dest
for(i in dest)
print i, src[i], dest[i] # output
}'
1 first first
2 second second
3 third third
But is there a way use a multidimensional array as the dest
array? Something like:
asort(src, dest[src[1]], "@ind_num_asc") # or dest[src[1]][]
(former produces second argument not an array
, latter syntax error
In reality the first argument of split
is $0
and I'm trying to group records.)
Of course I could use for
loop but my brain is stuck on testing this solution.