split()

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,

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,

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

output:

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!

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

Because:

  • Unless on GNU awk the variable WHINY_USERS is set.

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

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

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.

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

% 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 on c.l.a.

1 Like