Gnu/coreutils/Punctuation-Characters
Next: Punctuation Characters vs letters, Previous: Version sort is not the same as numeric sort, Up: Implementation Details [Contents][Index]
30.2.3 Punctuation Characters
Punctuation characters are sorted by ASCII order (rule 2.2).
$ touch 1.0.5_src.tar.gz 1.0_src.tar.gz $ ls -v -1 1.0.5_src.tar.gz 1.0_src.tar.gz
Why is 1.0.5_src.tar.gz
listed before 1.0_src.tar.gz
?
Based on the algorithm above, the strings are broken down into the following parts:
1 vs 1 (rule 3, all digit characters) . vs . (rule 2, all non-digit characters) 0 vs 0 (rule 3) . vs _src.tar.gz (rule 2) 5 vs empty string (no more character in the file name) _src.tar.gz vs empty string
The fourth parts (‘.
’ and _src.tar.gz
) are compared
lexically by ASCII order. The character ‘.
’ (ASCII value 46) is
smaller than ‘_
’ (ASCII value 95) - and should be listed before it.
Hence, 1.0.5_src.tar.gz
is listed first.
If a different character appears instead of the underscore (for
example, percent sign ‘%
’ ASCII value 37, which is smaller
than dot’s ASCII value of 46), that file will be listed first:
$ touch 1.0.5_src.tar.gz 1.0%zzzzz.gz 1.0%zzzzz.gz 1.0.5_src.tar.gz
The same reasoning applies to the following example: The character
‘.
’ has ASCII value 46, and is smaller than slash
character ‘/
’ ASCII value 47:
$ cat input5 3.0/ 3.0.5 $ sort -V input5 3.0.5 3.0/