Pierre-Jean wrote:
> I'm trying to sort a file containing accents and numbers,
> but can't find a way to do this correctly:
>
> - Without -V option, accents are correctly sorted, but not
> numbers.
> - With -V option, numbers are correctly sorted, but not
> accents.
>
> Here is an example:
>
> echo "
> A 10
> A 9
> E 10
> E 9
> e 10
> e 9
> é 10
> é 9
> F 10
> f 9 " | sort -f
>
> Return:
>
> A 10
> A 9
> e 10
> E 10
> é 10
> e 9
> E 9
> é 9
> F 10
> f 9
>
> --> Here accents are correctly sorted according to my
> locale: they are considered as a non accentuated letter.
> But numbers are not sorted in mathematical order.
>
> `sort -f -V` return:
The trick is to specify sorting with "-f" for the first column
and "-V" for the second. Then it does what you seem to want:
echo "
A 10
A 9
E 10
E 9
e 10
e 9
é 10
é 9
F 10
f 9" | sort -k1,1f -k2,2V
A 9
A 10
e 9
E 9
e 10
E 10
é 9
é 10
f 9
F 10
There are several examples showing how to use sort in the
documentation. Run "info coreutils sort" to display it,
or find it on-line:
https://www.gnu.org/s/coreutils/manual/html_node/sort-invocation.html