1

I was expecting @'s to be sorted together, but they interleaved with the non-@ versions. Does sort have an option for ASCII sorting? I didn't see something obvious in the man page.

$ echo '@x
> @y
> @z
> x
> y
> z' | sort
x
@x
y
@y
z
@z
KJ7LNW
  • 273
  • 1
  • 8

1 Answers1

3

This is locale-dependent. man sort includes:

*** 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.

You can set that just for the one command, like:

... | LC_ALL=C sort ...
Paul_Pedant
  • 8,228
  • 2
  • 18
  • 26
  • 2
    Or better use just `LC_COLLATE=C` which would work just as well. No need to throw the baby out with the bathwater -- an UTF-8 `LC_CTYPE` is perfectly fine, it's `LC_COLLATE` which is unasked for trouble. –  Jan 29 '21 at 23:14
  • @user414777 True here. I tend to globally export LC_ALL at the top of my scripts, because I rely on awk, sort, uniq, ls, tr etc to play nicely together. – Paul_Pedant Jan 30 '21 at 10:37