# split()

**URL:** <https://community.unix.com/t/split/269246>\
**Category:** Shell Programming and Scripting\
**Created:** [July 10, 2010, 3:25am UTC](https://community.unix.com/t/split/269246 "2010-07-10T03:25:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phoeberunner](https://community.unix.com/letter_avatar/phoeberunner/32/6_22734026db12803ebb3e059622ac3534.png) [@phoeberunner](https://community.unix.com/u/phoeberunner)\
**Post date:** [July 10, 2010, 3:25am UTC](https://community.unix.com/t/split/269246/1 "2010-07-10T03:25:13Z")

</div>

Hi there,

Can someone tell me why the why the element of output is not the same order as the original data?

Below is the value of column 11 of 2nd line,

```nohighlight
67000051,67091593,67098777,67101698,67105516,67108547,67109402,67126207,67133224,67136702,67137678,67139049,67142779,67145435,67148052,67154958,67155999,67161176,67185088,67195102,67199563,67205220,67206405,67207119,67210767,

```

Here is my awk command,

```nohighlight
awk 'NR==2 {split($11,a,",");for (i in a) print a}' refseq.txt

```

output:

```nohighlight
67155999
67101698
67161176
67105516
67185088
67108547
67109402
67126207
67133224
67136702
67195102
67137678
67199563
67139049
67205220
67142779
67206405
67145435
67000051
67207119
67148052
67091593
67210767
67154958
67098777

```

Thanks!

---

<div class="post-metadata">

**Author:** ![bartus11](https://community.unix.com/user_avatar/community.unix.com/bartus11/32/1418_2.png) [@bartus11](https://community.unix.com/u/bartus11)\
**Post date:** [July 10, 2010, 3:53am UTC](https://community.unix.com/t/split/269246/2 "2010-07-10T03:53:12Z")

</div>

```nohighlight
awk -vRS="," -vORS="\n" '//' file

```

---

<div class="post-metadata">

**Author:** ![radoulov](https://community.unix.com/user_avatar/community.unix.com/radoulov/32/489_2.png) [@radoulov](https://community.unix.com/u/radoulov)\
**Post date:** [July 10, 2010, 4:41am UTC](https://community.unix.com/t/split/269246/3 "2010-07-10T04:41:15Z")

</div>

> [@phoeberunner](#):
>
> Can someone tell me why the why the element of output is not the same order as the original data?  
> [...]

Because:

> [@](#):
>
> The order in which elements of the array are accessed by this statement is determined  
> by the internal arrangement of the array elements within awk and cannot be controlled or  
> changed\*.

- Unless on GNU awk the variable WHINY\_USERS is set.

If you want to preserve to order you could use something like this:

```plaintext
awk 'NR == 2 {
  n = split($11, a, ",")
  for (i = 1; i <= n; i ++) 
    print a
    }' refseq.txt

```

---

<div class="post-metadata">

**Author:** ![clx](https://community.unix.com/letter_avatar/clx/32/6_22734026db12803ebb3e059622ac3534.png) [@clx](https://community.unix.com/u/clx)\
**Post date:** [July 15, 2010, 9:42am UTC](https://community.unix.com/t/split/269246/4 "2010-07-15T09:42:58Z")

</div>

> [@radoulov](#):
>
> Unless on GNU awk the variable WHINY\_USERS is set.

Could you please tell how to use this variable..?  
I have been searching for a long time about this variable but couldn't find any documentation on this.

Thanks.

---

<div class="post-metadata">

**Author:** ![radoulov](https://community.unix.com/user_avatar/community.unix.com/radoulov/32/489_2.png) [@radoulov](https://community.unix.com/u/radoulov)\
**Post date:** [July 15, 2010, 10:08am UTC](https://community.unix.com/t/split/269246/5 "2010-07-15T10:08:32Z")

</div>

It's an undocumented feature.  
Setting WHINY\_USERS affects the array index sorting in GNU awk (the order is ASCIIbetical):

```plaintext
% print -l {a-l} |
  awk 'END {
    for (L in letters)
  print L
}
  { letters[$1] }'
h
i
j
k
l
a
b
c
d
e
f
g
% print -l {a-l} |
WHINY_USERS= awk 'END {
    for (L in letters)
  print L
}
  { letters[$1] }'
a
b
c
d
e
f
g
h
i
j
k
l

```

There was a recent [discussion](http://groups.google.com/group/comp.lang.awk/browse_thread/thread/c26b62a399ec85eb) on c.l.a.
