Search code examples
sortingrowmultiple-columnsautohotkeyword-frequency

How can AutoHotkey keep the order of the second column while sorting the numbers in the first column in descending order?


Sorting with AutoHotkey by "CL" results in an optimal order in the word column (sorted alphanumerically from top to bottom: 1, 2, 10, 11, a, ä, aa, aä and so on).

$F3::
frequency_word :=
(
"2  bb
2   aa
1   b
1   a
3   bbb
3   aaa"
)
Sort, frequency_word, CL
; Sort, frequency_word, R
MsgBox, 262144, Note, % frequency_word
return

Output

1   a
1   b
2   aa
2   bb
3   aaa
3   bbb

If "Sort, frequency_word, R" is then used, the result is as follows:

3   bbb
3   aaa
2   bb
2   aa
1   b
1   a

Here, only the order of the numbers in the first column is to be sorted in descending order from top to bottom, without changing the order of the word column. It should then look like this:

3   aaa
3   bbb
2   aa
2   bb
1   a
1   b

With R N and

frequency_word := 
(
1   a
1   b
2   aa
2   bb
)`

the output is:

2   aa
2   bb
1   b
1   a

Here is a relevant source: https://www.autohotkey.com/docs/commands/Sort.htm.


Solution

  • Variables created by regex can be stored in an array to sort the elements (autohotkey.com/board/topic/93570-sortArray2).