# sorting numeric array

**URL:** <https://community.unix.com/t/sorting-numeric-array/270935>\
**Category:** Shell Programming and Scripting\
**Created:** [August 5, 2010, 1:52pm UTC](https://community.unix.com/t/sorting-numeric-array/270935 "2010-08-05T13:52:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phoeberunner](https://community.unix.com/letter_avatar/phoeberunner/32/6_449c533f586939b6e5f246632a46421f.png) [@phoeberunner](https://community.unix.com/u/phoeberunner)\
**Post date:** [August 5, 2010, 1:52pm UTC](https://community.unix.com/t/sorting-numeric-array/270935/1 "2010-08-05T13:52:56Z")

</div>

Hi,

I would like to do the following sorting, but the output is not what i expected. Why 222 and 2222 are not at the last two elements of array?

```nohighlight
awk 'BEGIN{a[1]="22";a[2]="2222";a[3]="33";a[4]="44";a[5]="222";a[6]="11";a[7]="22";a[8]="33";asort(a); for (i=1;i<=8;i++) print a}'
11
22
22
222
2222
33
33
44

```

thanks,  
phoebe

---

<div class="post-metadata">

**Author:** ![bluejayek](https://community.unix.com/letter_avatar/bluejayek/32/6_449c533f586939b6e5f246632a46421f.png) [@bluejayek](https://community.unix.com/u/bluejayek)\
**Post date:** [August 5, 2010, 1:59pm UTC](https://community.unix.com/t/sorting-numeric-array/270935/2 "2010-08-05T13:59:41Z")

</div>

Apparently asort() sorts the array elements as strings rather then integers.
