Sort command doesn't sort '@' character correctly
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=. -fstack-protector-stron> uname output: Linux ubuntu 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_> Machine Type: x86_64-pc-linux-gnu Bash Version: 5.0 Patch Level: 17 Release Status: release Description: sorting lines where some starts with @ and some doesn't, it will not sort the lines correct Repeat-By: echo "xxaxxon" > test.txt echo "@zorg" >> test.txt echo "@jupiterlander" >> test.txt cat test.txt | sort Note it prints out: @jupiterlander xxaxxon @zorg Expected: @jupiterlander @zorg xxaxxon
Re: Sort command doesn't sort '@' character correctly
On 5/20/21 12:43 PM, Michael Jensen wrote: > Configuration Information [Automatically generated, do not change]: > Machine: x86_64 > OS: linux-gnu > Compiler: gcc > Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=. > -fstack-protector-stron> > uname output: Linux ubuntu 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 > 17:39:42 UTC 2021 x86_64 x86_> > Machine Type: x86_64-pc-linux-gnu > > Bash Version: 5.0 > Patch Level: 17 > Release Status: release > > Description: > sorting lines where some starts with @ and some doesn't, it will not > sort the lines correct > > Repeat-By: > > echo "xxaxxon" > test.txt > echo "@zorg" >> test.txt > echo "@jupiterlander" >> test.txt > cat test.txt | sort > > Note it prints out: > > @jupiterlander > xxaxxon > @zorg > > Expected: > > @jupiterlander > @zorg > xxaxxon The "sort" utility is not part of bash, so this is the wrong mailing list for the question. However, you will probably find that your vendor's "sort" utility will act as you expect, if you invoke it like this: cat test.txt | LC_ALL=C sort -- Eli Schwartz Arch Linux Bug Wrangler and Trusted User OpenPGP_signature Description: OpenPGP digital signature
Re: Sort command doesn't sort '@' character correctly
On Thu, May 20, 2021 at 04:43:49PM +, Michael Jensen wrote: > Repeat-By: > > echo "xxaxxon" > test.txt > echo "@zorg" >> test.txt > echo "@jupiterlander" >> test.txt > cat test.txt | sort > > Note it prints out: > > @jupiterlander > xxaxxon > @zorg > > Expected: > > @jupiterlander > @zorg > xxaxxon The sort command is not part of bash; it's part of your operating system. If you believe it's misbehaving for your locale, you should file a bug report with your operating system vendor. However, it's possible that this is "working as intended" for your locale, which is a thing that -- once again -- your operating system vendor has decided. The behaviors of locales tend to be pretty arbitrary and surprising. If you want strict ASCII-based sorting, with no characters ignored, then you should use the "POSIX" or "C" locale setting. For example: unicorn:~$ printf '%s\n' xyz @zorg @jupiter | sort @jupiter xyz @zorg unicorn:~$ printf '%s\n' xyz @zorg @jupiter | LC_COLLATE=POSIX sort @jupiter @zorg xyz Hope this helps.