sort mystery


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort mystery
# 1  
Old 04-16-2010
sort mystery

Hi everyone,

I can't seem to understand the behavior of sort on a particular case.

Code:
cat tmp25
1    a
10    b
20    c
2    d

I do that:

Code:
sort -k1,1 tmp25
1    a
10    b
2    d
20    c

This one I understand, it's what i expected, from a string point of view 1<10<2<20

Code:
sort -k1 tmp25
10    b
1    a
20    c
2    d

But this one????

Anyone understands why it gives that order? Smilie
Thanks!!

Anthony
# 2  
Old 04-16-2010
I get same results for both the commands
Code:
$ sort -k1,1 file
1    a
10    b
2    d
20    c
$ sort -k1 file
1    a
10    b
2    d
20    c

# 3  
Old 04-16-2010
That's odd..

It's a direct copy/paste from my terminal....:

Code:
14:33:55 anthony:~$ echo -e "1\ta\n10\tb\n20\tc\n2\td" | sort -k1,1
1    a
10    b
2    d
20    c
14:33:56 anthony:~$ echo -e "1\ta\n10\tb\n20\tc\n2\td" | sort -k1
10    b
1    a
20    c
2    d
14:33:56 anthony:~$

# 4  
Old 04-16-2010
what did you expect?
Code:
sort -n -k1,1 tmp25

# 5  
Old 04-16-2010
Because in the second sort where you say that the key is one character long, the sort program does not necessarily maintain keys that are equal on a fifo basis.
# 6  
Old 04-16-2010
Hi vgersh99,
Thanks but I actually want a sort based on the string values. I try to understand that 2nd output as it's a mystery to me!

Jgt,
wait i'm not sure I understand. i thought -kX1,Y1 -kX2, Y2... meant that the sort were to happen on field X1 to Y1 and to X2 to Y2. Does it have to do with the position of CHARACTER, not field??
# 7  
Old 04-16-2010
Can you modify your input data, maybe you have already saved the unsorted file to disk.
Change the tmp25 file so that the file actually is
10<tab>a
1<sp><tab>b
20<tab>c
2<sp><tab>d

Where <sp> is space and <tab> is tab.
It may be that your sort program is restricting the length of key1 to the shortest key 1.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell functions mystery

so i noticed that when a shell script has a function defined in it, running "sh -x" on that shell script from the command line doesnt show what the function is doing. i like this. is there anyway for anyone to get around that? to be able to see exactly what a function or functions are doing? (4 Replies)
Discussion started by: SkySmart
4 Replies

2. UNIX for Advanced & Expert Users

Apache Mod_rewrite Mystery

Hi Folks, I am running on a CentOS 6.3 server, whose primary function until recently has been my Zimbra mail server exclusively. I added wordpress and I have not been disappointed, with this one exception of Apache mod_rewrite. I have already tried to set selinux to permisive to eliminate that... (5 Replies)
Discussion started by: cjm51213
5 Replies

3. UNIX for Dummies Questions & Answers

File permission mystery ?

Hello, running AIX 6.1 # ls -la /home/user1 drwxrwxrwx 8 user1 staff 4096 Apr 19 2011 . drwxr-xr-x 8 bin bin 256 Feb 08 2011 .. drwx---r-x 2 user1 staff 256 Apr 13 2011 dir1 # su - user2 $ cd /home/user1 $ ls dir1 ls: dir1: The file... (1 Reply)
Discussion started by: vilius
1 Replies

4. Shell Programming and Scripting

Mystery about Case Statement

Can I make use of two command variable in case statement case $2 $3 in stp) Firewall disabled echo " Changing the http Proxy configuration " ;; str) Firewall enabled echo " Setting right http Proxy... (4 Replies)
Discussion started by: raghunsi
4 Replies

5. Filesystems, Disks and Memory

I/O Error Mystery

I burned identical raw encrypted data to three cds using my new external Toshiba drive. My internal IBM read only drive does not get an I/O Error when reading in Circumstance #1, but does get an I/O Error in Circumstance #2. But, the Toshiba drive can do both circumstances without an error. ... (1 Reply)
Discussion started by: darkstarxor
1 Replies

6. UNIX for Advanced & Expert Users

A perplexing mystery

A perplexing mystery... please note that i am not a lacky, and the error below is misleading recently something i do all the time broke (a script). now when i run this script i get this error. /usr/bin/awk: 0403-027 The parameter list is too long. note that the (parameter list is... (9 Replies)
Discussion started by: nullwhat
9 Replies

7. Solaris

The Mystery Directory

Hello Everyone, I am currently running a large Server with Veritas Volumen Manager, attached to a EMC. uname -a SunOS 5.8 Generic_117350-47 sun4u sparc SUNW,Sun-Fire-880 I have one directory that tends to change to a file.Once in a while and always in different time.The file is the... (1 Reply)
Discussion started by: Peterh
1 Replies

8. IP Networking

Traceroute and Whois mystery

Hey folks, I've been charged with the job of finding out who's been screwing around with the download counts on our site. So now I have this huge list of IP's that I supposed to match to such and such developer. I was told by one guy that I should just do a traceroute and that'd tell me where... (2 Replies)
Discussion started by: DumDum
2 Replies

9. Filesystems, Disks and Memory

terminal/port (serial) lock up mystery! SCO 5.0

Sorta new to Unix. great site here. I have SCO server with (5) 16 port Digi-boards and 5 line printers. For 3 years we've had no problems, till now... All of a sudden I get terminals and printers locking up. Killed the PID's for these particular situations. No help. So I disable the tty post... (10 Replies)
Discussion started by: ftn96
10 Replies
Login or Register to Ask a Question