title: alphanumeric or "Version sort" in awk array traversal
body: <p>I work with bioinformatic files that have a combination of characters and numbers in a row like below</p>
  <p>EDIT updated Example</p>
  <pre><code>chr1    1    100
  chr10   1    500
  chr2    33   52
  chr5    11   66
  chr22   99   1052
  chr11   444  2141
  chr2    555  1200
  chr7    300   444
  chr7    44   222
  chr21   24   6023
  chr16   224  5521
  chr3    3    200
  chrX    6234    79593
  chr1    5291    5500
  chrY    204  310
  </code></pre>
  <p>which I want to sort like this</p>
  <pre><code>chr1    1    100
  chr1    5291    5500
  chr2    33   52
  chr2    555  1200
  chr3    3    200
  chr5    11   66
  chr7    44   222
  chr7    300   444
  chr10   1    500
  chr11   444  2141
  chr16   224  5521
  chr21   24   6023
  chr22   99   1052
  chrX    6234    79593
  chrY    204  310
  </code></pre>
  <p>I am using controlled array transversal to sort these as I scan them with for loops, but the established sorting methods are either numerical, string, or type sorting.  I would like something exactly like the GNU <code>sort -V</code> sorting.   In the link below I see that I can build a custom function for sorting, but I am not sure how to do this for alphanumeric values.</p>
  <p>I had the idea to do something like this and sort the letter values and numeric parts separately and the figure out how to combine them, but I'm not sure exactly how to do that.</p>
  <pre><code>echo &quot;d23FgE55&quot; | awk '{alph=$1;num=$1;gsub(&quot;[0-9]+&quot;,&quot;-&quot;,alph);gsub(&quot;[A-z]+&quot;,&quot;-&quot;,num);print alph,num}'
  d-FgE- -23-55
  </code></pre>
  <p><strong>EDIT</strong></p>
  <p>I apologize, one of the answers reminded me of some of the more complicated examples I run into sometimes that made me ask about something closer to <code>sort -V</code> behavior.</p>
  <p><strong>Unsorted example</strong></p>
  <pre><code>chr1_KI270708v1_random  9240458 9393655
  chrUn_KI270589v1        5789405 6182867
  chr19_GL383576v1_alt    4363702 4753141
  chr8_KI270820v1_alt     1008865 1426444
  chrUn_GL000220v1        7612088 7825236
  chrUn_KI270591v1        9457975 9812609
  chr19_GL949747v2_alt    1578276 2033118
  chr13_KI270841v1_alt    8680841 9033557
  chr17_KI270859v1_alt    3996864 4344945
  chr20_GL383577v2_alt    3002112 3480396
  chrUn_KI270322v1        1563181 1629375
  chrUn_KI270419v1        5482364 5893900
  chrUn_KI270310v1        4229845 4626802
  chr17_KI270907v1_alt    1735306 2201566
  chr9    2052238 2476827
  chr1_KI270713v1_random  7260088 7358876
  chr19_KI270891v1_alt    7485890 7719006
  chr19_KI270917v1_alt    7816269 7864474
  chrUn_KI270378v1        8848225 9158581
  chr19_KI270933v1_alt    1600444 2095219
  chr3_KI270937v1_alt     9902343 10113942
  chr12_KI270904v1_alt    6924313 7067502
  chrUn_GL000214v1        2468418 2728693
  chr19_KI270884v1_alt    2760167 3027068
  chrUn_KI270582v1        6390491 6398266
  chr5_KI270897v1_alt     324409  548890
  chr1_GL383520v2_alt     3718510 3948906
  chr19_KI270888v1_alt    3809944 3824324
  chr11_JH159137v1_alt    6090599 6480896
  chr1_KI270762v1_alt     4196600 4684821
  chr11_KI270831v1_alt    2112401 2490081
  chr5_GL339449v2_alt     7220557 7718111
  chr19_KI270889v1_alt    8709969 8823256
  chr19_KI270931v1_alt    6356216 6811953
  chr5_GL383530v1_alt     109389  128439
  chr11_KI270927v1_alt    2119470 2348459
  chr17_KI270730v1_random 404268  854145
  chrUn_KI270387v1        7430161 7648856
  chr10   2656835 2873499
  chr19_GL383573v1_alt    7863497 7896279
  chrUn_KI270741v1        1292450 1371680
  chrUn_KI270335v1        7360266 7748998
  chr9_GL383539v1_alt     3394859 3499461
  chrX    4490524 4892623
  chrUn_KI270311v1        963681  1069745
  chr11_JH159136v1_alt    8171978 8319851
  chr17_JH159148v1_alt    3708868 3984631
  chrUn_KI270544v1        7025954 7392905
  chr19_KI270888v1_alt    9683785 10166473
  chrUn_KI270521v1        6924036 7001552
  chr1_KI270710v1_random  8843336 9304602
  chr19_GL949746v1_alt    8572018 8832793
  chrUn_KI270322v1        9392841 9512920
  chrUn_KI270366v1        3332191 3576201
  chr13_KI270841v1_alt    9033828 9276044
  chr19_GL949748v2_alt    3321575 3743545
  chr16   3704062 4122526
  chr17_GL383563v3_alt    7476487 7845527
  chr8_KI270810v1_alt     8499569 8873953
  chr22_KI270732v1_random 9187626 9418154
  chr20_GL383577v2_alt    3031797 3421627
  chr9_GL383541v1_alt     3771485 3927905
  chr9_KI270720v1_random  8948742 9157627
  chr16_KI270854v1_alt    7278604 7297845
  chr1_KI270763v1_alt     1518275 1527443
  chrUn_KI270517v1        3377374 3454859
  chr15_KI270850v1_alt    6358541 6822565
  chr22_KB663609v1_alt    4944645 4971886
  chr7_KI270806v1_alt     9032201 9471652
  chrUn_KI270438v1        8523562 8944980
  chr17_KI270730v1_random 3544067 3796807
  chr18   1856815 2144546
  chr20_KI270869v1_alt    2269342 2353172
  chr5_GL383530v1_alt     2139701 2285854
  chr8_KI270819v1_alt     7048265 7503415
  chr17_JH159148v1_alt    7040113 7042904
  chr5_KI270793v1_alt     9363008 9816819
  chr19_KI270931v1_alt    1794178 2143519
  chr3_KI270778v1_alt     2228100 2549359
  chr19_KI270932v1_alt    8320855 8486835
  chr12_GL877876v1_alt    3736839 3820171
  chr12_GL877876v1_alt    2805577 2974710
  chr4_KI270789v1_alt     3309756 3669565
  chr19_KI270917v1_alt    9443280 9678387
  chr11_KI270831v1_alt    8603751 9028904
  chrUn_KI270387v1        5189812 5439563
  chrUn_KI270507v1        599827  666674
  chr1_KI270711v1_random  6111532 6446935
  chr2_KI270773v1_alt     8604675 8922311
  chr16_KI270856v1_alt    5855373 6089898
  chr3    3097856 3436204
  chr13_KI270840v1_alt    3127654 3295739
  chr15_KI270849v1_alt    8948327 9336376
  chr18_KI270863v1_alt    3984764 4166006
  chr19_KI270920v1_alt    5554949 5919294
  chr12   6624798 7106478
  chr4_GL383528v1_alt     2099770 2280753
  chr2_KI270769v1_alt     8706329 9147304
  chr8_KI270812v1_alt     6146462 6388606
  </code></pre>
  <p><strong>Sorted Output</strong></p>
  <pre><code>chr1_GL383520v2_alt     3718510 3948906
  chr1_KI270708v1_random  9240458 9393655
  chr1_KI270710v1_random  8843336 9304602
  chr1_KI270711v1_random  6111532 6446935
  chr1_KI270713v1_random  7260088 7358876
  chr1_KI270762v1_alt     4196600 4684821
  chr1_KI270763v1_alt     1518275 1527443
  chr2_KI270769v1_alt     8706329 9147304
  chr2_KI270773v1_alt     8604675 8922311
  chr3    3097856 3436204
  chr3_KI270778v1_alt     2228100 2549359
  chr3_KI270937v1_alt     9902343 10113942
  chr4_GL383528v1_alt     2099770 2280753
  chr4_KI270789v1_alt     3309756 3669565
  chr5_GL339449v2_alt     7220557 7718111
  chr5_GL383530v1_alt     109389  128439
  chr5_GL383530v1_alt     2139701 2285854
  chr5_KI270793v1_alt     9363008 9816819
  chr5_KI270897v1_alt     324409  548890
  chr7_KI270806v1_alt     9032201 9471652
  chr8_KI270810v1_alt     8499569 8873953
  chr8_KI270812v1_alt     6146462 6388606
  chr8_KI270819v1_alt     7048265 7503415
  chr8_KI270820v1_alt     1008865 1426444
  chr9    2052238 2476827
  chr9_GL383539v1_alt     3394859 3499461
  chr9_GL383541v1_alt     3771485 3927905
  chr9_KI270720v1_random  8948742 9157627
  chr10   2656835 2873499
  chr11_JH159136v1_alt    8171978 8319851
  chr11_JH159137v1_alt    6090599 6480896
  chr11_KI270831v1_alt    2112401 2490081
  chr11_KI270831v1_alt    8603751 9028904
  chr11_KI270927v1_alt    2119470 2348459
  chr12   6624798 7106478
  chr12_GL877876v1_alt    2805577 2974710
  chr12_GL877876v1_alt    3736839 3820171
  chr12_KI270904v1_alt    6924313 7067502
  chr13_KI270840v1_alt    3127654 3295739
  chr13_KI270841v1_alt    8680841 9033557
  chr13_KI270841v1_alt    9033828 9276044
  chr15_KI270849v1_alt    8948327 9336376
  chr15_KI270850v1_alt    6358541 6822565
  chr16   3704062 4122526
  chr16_KI270854v1_alt    7278604 7297845
  chr16_KI270856v1_alt    5855373 6089898
  chr17_GL383563v3_alt    7476487 7845527
  chr17_JH159148v1_alt    3708868 3984631
  chr17_JH159148v1_alt    7040113 7042904
  chr17_KI270730v1_random 404268  854145
  chr17_KI270730v1_random 3544067 3796807
  chr17_KI270859v1_alt    3996864 4344945
  chr17_KI270907v1_alt    1735306 2201566
  chr18   1856815 2144546
  chr18_KI270863v1_alt    3984764 4166006
  chr19_GL383573v1_alt    7863497 7896279
  chr19_GL383576v1_alt    4363702 4753141
  chr19_GL949746v1_alt    8572018 8832793
  chr19_GL949747v2_alt    1578276 2033118
  chr19_GL949748v2_alt    3321575 3743545
  chr19_KI270884v1_alt    2760167 3027068
  chr19_KI270888v1_alt    3809944 3824324
  chr19_KI270888v1_alt    9683785 10166473
  chr19_KI270889v1_alt    8709969 8823256
  chr19_KI270891v1_alt    7485890 7719006
  chr19_KI270917v1_alt    7816269 7864474
  chr19_KI270917v1_alt    9443280 9678387
  chr19_KI270920v1_alt    5554949 5919294
  chr19_KI270931v1_alt    1794178 2143519
  chr19_KI270931v1_alt    6356216 6811953
  chr19_KI270932v1_alt    8320855 8486835
  chr19_KI270933v1_alt    1600444 2095219
  chr20_GL383577v2_alt    3002112 3480396
  chr20_GL383577v2_alt    3031797 3421627
  chr20_KI270869v1_alt    2269342 2353172
  chr22_KB663609v1_alt    4944645 4971886
  chr22_KI270732v1_random 9187626 9418154
  chrUn_GL000214v1        2468418 2728693
  chrUn_GL000220v1        7612088 7825236
  chrUn_KI270310v1        4229845 4626802
  chrUn_KI270311v1        963681  1069745
  chrUn_KI270322v1        1563181 1629375
  chrUn_KI270322v1        9392841 9512920
  chrUn_KI270335v1        7360266 7748998
  chrUn_KI270366v1        3332191 3576201
  chrUn_KI270378v1        8848225 9158581
  chrUn_KI270387v1        5189812 5439563
  chrUn_KI270387v1        7430161 7648856
  chrUn_KI270419v1        5482364 5893900
  chrUn_KI270438v1        8523562 8944980
  chrUn_KI270507v1        599827  666674
  chrUn_KI270517v1        3377374 3454859
  chrUn_KI270521v1        6924036 7001552
  chrUn_KI270544v1        7025954 7392905
  chrUn_KI270582v1        6390491 6398266
  chrUn_KI270589v1        5789405 6182867
  chrUn_KI270591v1        9457975 9812609
  chrUn_KI270741v1        1292450 1371680
  chrX    4490524 4892623
  </code></pre>
  <p><a href="https://www.gnu.org/software/gawk/manual/html_node/Controlling-Array-Traversal.html" rel="nofollow noreferrer">https://www.gnu.org/software/gawk/manual/html_node/Controlling-Array-Traversal.html</a></p>