coreutils: Tilde ~ character
30.2.5 Tilde ‘~’ character
--------------------------
Rule 2.2.2 dictates that tilde character ‘‘~’’ (ASCII 126) sorts before
all other non-digit characters, including an empty part.
$ cat input7
1
1%
1.2
1~
~
$ sort -V input7
~
1~
1
1%
1.2
The sorting algorithm starts by breaking down the string into
non-digits (rule 2) and digits parts (rule 3).
In the above input file, only the last line in the input file starts
with a non-digit (‘‘~’’). This is the first part. All other lines in
the input file start with a digit - their first non-digit part is empty.
Based on rule 2.2.2, tilde ‘‘~’’ sorts before all other non-digits
including the empty part - hence it comes before all other strings, and
is listed first in the sorted output.
The remaining lines (‘1’, ‘1%’, ‘1.2’, ‘1~’) follow similar logic:
The digit part is extracted (1 for all strings) and compares identical.
The following extracted parts for the remaining input lines are: empty
part, ‘%’, ‘.’, ‘~’.
Tilde sorts before all others, hence the line ‘1~’ appears next.
The remaining lines (‘1’, ‘1%’, ‘1.2’) are sorted based on previously
explained rules.