bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#12907: Possible Bug in sort core utility


From: Eric Blake
Subject: bug#12907: Possible Bug in sort core utility
Date: Fri, 16 Nov 2012 13:09:58 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121029 Thunderbird/16.0.2

tag 12907 notabug
thanks

On 11/16/2012 11:06 AM, Coffey, Terrence (Terrence) **CTR** wrote:
> Hi,
> I think I might have located a bug. I'm using Redhat 6.3.

Thanks for the report.  However, I suspect that you are hitting this
FAQ, and not a bug in sort itself:
https://www.gnu.org/software/coreutils/faq/#Sort-does-not-sort-in-normal-order_0021

Unfortunately, the 'sort' version shippted in RHEL 6.3 is too old to
support the --debug option, but upgrading to a newer version will help
shed some insight into your problems.

> address@hidden tmp]$ ls -Asl  /tmp |sort -k11 -k7M -k8n -k9,10

As I don't have the same 'ls -Asl /tmp' output, I took your output and
put in in a temp file of my own.  Now, on that file, and with the sort
8.15 in Fedora 17, I get:

$ LC_ALL=en_US.UTF-8 sort --debug -k11 -k7M -k8n -k9,10 tmpfile
sort: using `en_US.UTF-8' sorting rules
sort: leading blanks are significant in key 1; consider also specifying `b'
sort: key 3 is numeric and spans multiple fields
sort: leading blanks are significant in key 4; consider also specifying `b'
total 76
        ^ no match for key
        ^ no match for key
        ^ no match for key
        ^ no match for key
________
0 -rw-------. 1 root   root      0 Nov  9 15:06 yum.log
                                                       ^ no match for key
                                   ___
                                        _
                                         ______________
_______________________________________________________
4 -r--r--r--. 1 root   root     11 Nov  9 17:37 .X0-lock
                                                        ^ no match for key
                                   ___
                                        _
                                         _______________
________________________________________________________

...

Wow - just that much information is quite useful.  You aren't sorting
what you thought you were sorting.

> 
> The filename is key 11 so I was expecting to see all the dot files group 
> together

The filename is NOT field 11, but field 10 (fields start with 1, not 0).
 Furthermore, the debug option is warning you that unterminated -k
specifications are risky; for example, it is better to use -k7,7M than
-k7M.  Also, it is warning you that -k11 includes leading space, which
may affect the sort (depending on your locale).  Paul already pointed
out that your choice of locale may be important (en_US.UTF-8 typically
does a dictionary sort, ignoring punctuation, but '.' is punctuation).

> I'm try to get a listing of dot file sorted by date and all other files 
> sorted by date. I'd like all the dot file to appears before all other files.

Here's something closer, but it still has a fatal flaw - the moment you
request to sort by dot files first, you have specified that key takes
priority over dates.

$ LC_ALL=C sort -k10b -k7,7M -k8,8nb -k9,9 tmpfile
total 76
4 drwxrwxrwt. 2 root   root   4096 Nov  9 18:35 .ICE-unix
4 -r--r--r--. 1 root   root     11 Nov  9 17:37 .X0-lock
4 drwxrwxrwt. 2 root   root   4096 Nov  9 18:35 .X11-unix
4 -r--r--r--. 1 root   root     11 Nov  9 18:35 .X2-lock
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 .esd-500
4 -rw-rw-r--. 1 WFUser WFUser    5 Nov 16 18:14 .tc
4 -rw-rw-r--. 1 WFUser WFUser    5 Nov 16 18:14 .tc2
4 -rw-rw-r--. 1 WFUser WFUser    5 Nov 16 18:18 .tc3
4 -rw-rw-r--. 1 WFUser WFUser    5 Nov 16 18:15 .tc4
4 drwx------. 2 root   root   4096 Nov  9 18:35 keyring-kjLYun
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 keyring-nQ6lMb
4 drwx------. 2 WFUser WFUser 4096 Nov  9 18:20 orbit-WFUser
4 drwx------. 2 gdm    gdm    4096 Nov  9 17:39 orbit-gdm
4 drwx------. 2 root   root   4096 Nov  9 18:35 orbit-root
4 drwx------. 2 gdm    gdm    4096 Nov  9 17:40 pulse-Jkx9hhtHj4dy
4 drwx------. 2 root   root   4096 Nov  9 18:35 pulse-TSaTZvcbd1kc
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 pulse-g9SlRO3UEqGg
4 drwx------. 2 root   root   4096 Nov  9 18:35 ssh-BRSEI10523
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 virtual-WFUser.AVmQkN
0 -rw-------. 1 root   root      0 Nov  9 15:06 yum.log

Really, the ONLY way you are going to sort two independent chunks of
your list by date is to instead concatenate two independently sorted
chunks, and realize that ls already does the date sorting that you
desire.  Perhaps you are really looking for:

(set -f; ls -lsd --sort=date /tmp/.[!.] /tmp/.?*; ls -ls --sort=date /tmp)

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]