4

I would like to sort an array with POSIX Awk, however I have discovered that:

  • asort()
  • asorti()
  • PROCINFO["sorted_in"]

are all GNU extensions. Can this be done with without GNU Awk?

1
2

Here is an example:

function arr_sort(ary,   x, y, z) {
  for (x in arr) {
    y = arr[x]
    z = x - 1
    while (z && arr[z] > y) {
      arr[z + 1] = arr[z]
      z--
    }
    arr[z + 1] = y
  }
}

Source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.