# Sort descending numeric on the index field func cmp (a, b) { return b.index <=> a.index; }; begin { @records = []; # Define as an array, else auto-create will make a map } @records[NR] = $*; # Accumulate end { f = cmp; @records = sort(@records, f); for (record in @records) { emit record; } }