March 2018
Beginner to intermediate
416 pages
9h 24m
English
GAWK provides a built-in function, asort( ), to sort the array on values. Numeric values come before string values in the sorting order. The following is the syntax for sorting the array:
Gn = asort(arr)
In the following example, we will use the asort() function to sort the array elements, as per the values assigned to them. The only side effect of using the asort() function with default parameters is that the array's original indexes will be lost and the new array is assigned an index from 1 to n as follows:
$ vi asort_arr.awkBEGIN { arr[30] = "volvo" arr[10] = "bmw" arr[20] = "audi" arr[50] = "toyota" arr["car"] = "ferrari" arr[70] = "renault" arr[110] = 20 arr[40] = "ford" arr["num"] = 10 arr[80] = ...Read now
Unlock full access