Sort function UNIX bug ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort function UNIX bug ???
# 1  
Old 12-12-2012
Hammer & Screwdriver 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

Code:
,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

Code:
,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
Code:
,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
Code:
,Test,RSD,VA,VA_Asset

is before
Code:
,Test,RSD,VA,VAFA

and how come
Code:
,Test,RSD,VA,VA_Liab

is not next
Code:
,Test,RSD,VA,VA_Asset

I am getting crazy ????Smilie Smilie


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

Code:
,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
# 2  
Old 12-12-2012
could you please show me this command and its ouput?

Code:
echo $LANG

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 12-12-2012
try this.

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


from the sort docs
Code:
  ---------- 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'.

This User Gave Thanks to frank_rizzo For This Post:
# 4  
Old 12-13-2012
echo $LANG

Code:
en_US.UTF-8

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

~% env

Code:
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
Code:
en_US.UTF-8

~% echo $LC_ALL
Code:
C


that did not change anything

~% sort test.txt

Code:
,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 !!!!! SmilieSmilie you found it !!!

if i execute

Code:
env LC_ALL=C sort test.txt

it work fine

Code:
,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)
Code:
env LC_ALL=C

then

Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Inconsistent results using sort function

Could you please advise on the following: I have two space-delimited files with 9 and 10 columns, respectively, with exactly the same values in column 1. However, the order of column 1 differs between the two files, so I want to sort both files by column 1, so that I can align them and... (6 Replies)
Discussion started by: aberg
6 Replies

2. What is on Your Mind?

Small bug in the Quick Editor function in postbit

Hey, There was a small bug in the Quick Editor function in postbit, but I fixed it (basically a double quote was missing from an element id): <div id="post_message_$post" class="neo-message-area">$post</div> Was <div id="post_message_$post class="neo-message-area">$post</div> Should... (1 Reply)
Discussion started by: Neo
1 Replies

3. Programming

Tweaked getpass() function gives an untraceable bug

I have customized the getpass() as follows: char* my_getpass(const char* str) { struct termios oflags, nflags; static char passwd; /* disabling echo */ tcgetattr(fileno(stdin), &oflags); nflags = oflags; nflags.c_lflag &= ~ECHO; nflags.c_lflag |= ECHONL; ... (3 Replies)
Discussion started by: royalibrahim
3 Replies

4. Shell Programming and Scripting

Bug in Function Call

Can anybody tell me where is the bug in this below mentioned function call. #The String Search File myString="${LOCATION}/config/stringFile.txt" # Functional Usage function usage() { if ; then echo "************************************************************" ... (5 Replies)
Discussion started by: baraghun
5 Replies

5. Homework & Coursework Questions

Sort function -- My First Unix Homework!

1. The problem statement, all variables and given/known data: To sort a data 2. Relevant commands, code, scripts, algorithms: The data provided is saved in dummy.txt and provided in LIBSVM format, but I think this information is redundant.. +1 1:2 2:4 4:3.2 -1 2:2.1 2:2.1 ... (4 Replies)
Discussion started by: eeweepoh
4 Replies

6. Shell Programming and Scripting

bash-function with array acting bizarre, bug?

Hello, basically what this script is supposed to do is showing a list of hosts that is given a number, that you will be able to choose from a list. A check is made to verify that the chosen number is within the array and this is where things go bad and I don't know why, bizarre. I've spent... (5 Replies)
Discussion started by: gand
5 Replies

7. Shell Programming and Scripting

sort function in perl

Hi, here is my perl script.This script creates an array and is sorting it using the in-built sort function in perl. #!/usr/local/bin/perl my number=6; my @num_arr=(1,2,3,4,5); my @array=(23,"$number","Hello",2.345,@num_arr); #printing the array print... (2 Replies)
Discussion started by: DILEEP410
2 Replies

8. Shell Programming and Scripting

Function Bug in script - need help

My script is erroring with: testtapemgr.sh: FTP_RETURNS: not found I cannot see what I am doing wrong..when it calls that function from the Volume returns function and says taht FTP_RETURNS is not found and exits out of the script. What am I not seeing here? #### Return Volume Function ... (4 Replies)
Discussion started by: gzs553
4 Replies

9. Programming

sort function

do any one knows where i can find an implementation in c for the sort function (2 Replies)
Discussion started by: dbargo
2 Replies
Login or Register to Ask a Question