Why do :
$ echo -e 'Q\ns\nV' | sort
Q s V
without changing the order of my list (taking in account the lower/uppercase ?)
In most languages,
s sorts before
V regardless of the case.
Sorting depends on localisation settings (
You could use:
LC_ALL=C sort if you wanted to sort according to the byte value order, but that may not do what you want if you're in a multi-byte locale.
If you want to sort in the order of your own language, but having uppercase letters before lowercase ones, you could do:
sed 's/./0&/g;s/0\([[:lower:]]\)/1\1/g' | sort | sed 's/.\(.\)/\1/g'
That would cause lower-case letters to be sorted after every other character.
$ print -l Q s d é f D É F V | sort d D é É f F Q s V $ print -l Q s d é f D É F V | sed 's/./0&/g;s/0\([[:lower:]]\)/1\1/g' | sort | sed 's/.\(.\)/\1/g' D É F Q V d é f s
That would only work in locales where collating elements are single characters only.
sort's sort order depends on your environment's locale settings. From the
*** WARNING *** The locale specified by the environment affects sort order. Set LC_ALL=C to get the traditional sort order that uses native byte values.
The POSIX or C locale will make
sort behave as expected:
reedm@www:~ $ echo -e 'Q\ns\nV' | LC_ALL='' sort Q s V reedm@www:~ $ echo -e 'Q\ns\nV' | LC_ALL='' sort --ignore-case Q s V reedm@www:~ $ echo -e 'Q\ns\nV' | LC_ALL='c' sort Q V s reedm@www:~ $ echo -e 'Q\ns\nV' | LC_ALL='c' sort --ignore-case Q s V