Sort function UNIX bug ???

Hello there

i have a funny behiavor of the sort fonction, i try it out on different Solaris machine and i have the same issue.
So i would like to see if there is a rationel explanation

here is some data in a file:test.txt

,Test,RSD,RSD_Asset
,Test,RSD,RSD_Credit
,Test,RSD,RSD_Liab
,Test,RSD,VA,VAFA,VAFA_Asset
,Test,RSD,VA,VAFA,VAFA_Credit
,Test,RSD,VA,VA_Liab
,Test,RSD,RSD_Mort
,Test,RSD,RSDA
,Test,RSD,RSD_Oper
,Test,RSD,VA
,Test,RSD,VA,VAFA
,Test,RSD,VA,VAFA,VAFA_Liab
,Test,RSD,VA,VA_Asset

now if i sort that file, i receive this
sort test.txt

,Test,RSD,RSDA
,Test,RSD,RSD_Asset
,Test,RSD,RSD_Credit
,Test,RSD,RSD_Liab
,Test,RSD,RSD_Mort
,Test,RSD,RSD_Oper
,Test,RSD,VA
,Test,RSD,VA,VA_Asset
,Test,RSD,VA,VAFA
,Test,RSD,VA,VAFA,VAFA_Asset
,Test,RSD,VA,VAFA,VAFA_Credit
,Test,RSD,VA,VAFA,VAFA_Liab
,Test,RSD,VA,VA_Liab

and here are a couple of strange things happening

1:
if you look the start of the file

,Test,RSD,RSDA
,Test,RSD,RSD_Asset
,Test,RSD,RSD_Credit

it seem that the charactere "_" is sorted after the alphabete (that is what i want)

2: but if you look further
how come

,Test,RSD,VA,VA_Asset

is before

,Test,RSD,VA,VAFA

and how come

,Test,RSD,VA,VA_Liab

is not next

,Test,RSD,VA,VA_Asset

I am getting crazy ????:confused: :eek:

I will like to have the following output (which make the more sence for the sorting fontion)

,Test,RSD,RSDA
,Test,RSD,RSD_Asset
,Test,RSD,RSD_Credit
,Test,RSD,RSD_Liab
,Test,RSD,RSD_Mort
,Test,RSD,RSD_Oper
,Test,RSD,VA
,Test,RSD,VA,VAFA
,Test,RSD,VA,VAFA,VAFA_Asset
,Test,RSD,VA,VAFA,VAFA_Credit
,Test,RSD,VA,VAFA,VAFA_Liab
,Test,RSD,VA,VA_Asset
,Test,RSD,VA,VA_Liab

thanks for your comments!!!
i am using
SunOS talos 5.10 Generic_147440-12 sun4u sparc SUNW,Sun-Fire-V490

could you please show me this command and its ouput?

echo $LANG
1 Like

try this.

env LC_ALL=C sort /path/to/you.file

from the sort docs

  ---------- Footnotes ----------

   (1) If you use a non-POSIX locale (e.g., by setting `LC_ALL' to
`en_US'), then `sort' may produce output that is sorted differently
than you're accustomed to.  In that case, set the `LC_ALL' environment
variable to `C'.  Note that setting only `LC_COLLATE' has two problems.
First, it is ineffective if `LC_ALL' is also set.  Second, it has
undefined behavior if `LC_CTYPE' (or `LANG', if `LC_CTYPE' is unset) is
set to an incompatible value.  For example, you get undefined behavior
if `LC_CTYPE' is `ja_JP.PCK' but `LC_COLLATE' is `en_US.UTF-8'.
1 Like

echo $LANG

en_US.UTF-8

---------- Post updated at 11:38 PM ---------- Previous update was at 11:30 PM ----------

~% env

USER=pilotlab
LOGNAME=pilotlab
HOME=/home/pilotlab
PATH=/usr/dt/bin:/usr/openwin/bin:/bin:/usr/bin:/usr/ucb:/usr/contrib/bin:/usr/local/bin:/usr/sbin:/usr/ccs/bin
MAIL=/var/mail//pilotlab
SHELL=/bin/tcsh
TZ=US/Eastern
LC_CTYPE=en_US.ISO8859-1
LC_COLLATE=en_US.ISO8859-1
LC_TIME=en_US.ISO8859-1
LC_NUMERIC=en_US.ISO8859-1
LC_MONETARY=en_US.ISO8859-1
LC_MESSAGES=C
SSH_CLIENT=9.49.136.160 53208 22
SSH_CONNECTION=9.49.136.160 53208 9.31.24.88 22
SSH_TTY=/dev/pts/23
TERM=xterm
DISPLAY=localhost:10.0
HOSTTYPE=sun4
VENDOR=sun
OSTYPE=solaris
MACHTYPE=sparc
SHLVL=1
PWD=/home/pilotlab
GROUP=algolab
HOST=talos
REMOTEHOST=sig-9-49-136-160.mts.ibm.com
CPLEXLICENSE=/mnts/master/cplex/cpxlicptr
LD_LIBRARY_PATH=/usr/lib:/usr/openwin/lib:/usr/sfw/lib
EDITOR=vi
MANPATH=/usr/share/man:/usr/local/man

~% echo $LANG

en_US.UTF-8

~% echo $LC_ALL

C

that did not change anything

~% sort test.txt

,Test,RSD,RSDA
,Test,RSD,RSD_Asset
,Test,RSD,RSD_Credit
,Test,RSD,RSD_Liab
,Test,RSD,RSD_Mort
,Test,RSD,RSD_Oper
,Test,RSD,VA
,Test,RSD,VA,VA_Asset
,Test,RSD,VA,VAFA
,Test,RSD,VA,VAFA,VAFA_Asset
,Test,RSD,VA,VAFA,VAFA_Credit
,Test,RSD,VA,VAFA,VAFA_Liab
,Test,RSD,VA,VA_Liab

if you sort it on your unix machine, does it sort it well ?

regards

---------- Post updated at 11:50 PM ---------- Previous update was at 11:38 PM ----------

Sorry it actually work !!!!! :b::b: you found it !!!

if i execute

env LC_ALL=C sort test.txt 

it work fine

,Test,RSD,RSDA
,Test,RSD,RSD_Asset
,Test,RSD,RSD_Credit
,Test,RSD,RSD_Liab
,Test,RSD,RSD_Mort
,Test,RSD,RSD_Oper
,Test,RSD,VA
,Test,RSD,VA,VAFA
,Test,RSD,VA,VAFA,VAFA_Asset
,Test,RSD,VA,VAFA,VAFA_Credit
,Test,RSD,VA,VAFA,VAFA_Liab
,Test,RSD,VA,VA_Asset
,Test,RSD,VA,VA_Liab

but if i do it in two step (like the way i tryed before)

env LC_ALL=C

then

sort test.txt 

the error is there

so i guess i need to review my locals
i can take care of that thanks a lot and that is really good to know (for me at least)

regards