Quote:
Originally Posted by
alister
... ... ...
While I've not removed it, I believe there is no need to use sort's -n option. Unless there exists a locale in which the digits do not sort from 0 to 9 -- if such a locale exists, I would truly appreciate being made of aware of it -- if the numbers are the same length, lexicographical and numerical sorting will yield identical results.
Regards,
Alister
In section 5.2.1 of the C Standard titled
Character Sets it says:
Quote:
In both the source and execution basic character sets, the
value of each character after 0 in the above list of decimal
digits shall be one greater than the value of the previous.
In the POSIX Standards, XBD section 6.1 titled
Portable Character Set places this requirement from the C Standard on all locales supported by a system conforming to the POSIX Standards or to the more stringent requirements of the Single UNIX Specification.
So, the -n isn't needed in sort when all of the strings of digits being sorted are all the same length.
Although it doesn't matter in this case, note that the same can't be said for uppercase letters nor lowercase letters. Adding 0 through 26 to 'a' ('A') to get the lowercase (uppercase) letters in sequence happens to work in supersets of ASCII, but it won't work in EBCDIC. There are gaps between 'i' and 'j' ('I' and 'J') and between 'r' and 's' ('R' and 'S') in EBCDIC.