Subject: bug#12907: closed (Re: bug#12907: Possible Bug in sort core utility)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 16 Nov 2012 20:29:02 +0000

Your bug report

#12907: Possible Bug in sort core utility

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
12907: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12907
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#12907: Possible Bug in sort core utility
From: Eric Blake <[email-masked]>
To: "Coffey, Terrence (Terrence) **CTR**" <[email-masked]>
Cc: [email-masked]
Date: Fri, 16 Nov 2012 13:09:58 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

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.

> [WFUser@RHEL63TEMP3942 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   [email-masked]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Subject: Possible Bug in sort core utility
From: "Coffey, Terrence (Terrence) **CTR**" <[email-masked]>
To: "[email-masked]" <[email-masked]>
Cc: "Coffey, Terrence \(Terrence\) **CTR**" <[email-masked]>
Date: Fri, 16 Nov 2012 18:06:06 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,
I think I might have located a bug. I'm using Redhat 6.3.
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.
Initially I was testing on 6.2 and noticed that the .(dot) files were not passed to sort. However this issue is fixed in 6.3.
However it does not appear to be able to sort dot files. The filename is key 11 so I was expecting to see all the dot files group together
Either at the start or end and to have these groups sorted chronographically. I've tried -k11 with and without d.

I've also tried to do a reverse sort but it did not seem to get the desired result. I'm not sure if I'm not using the options correctly
Or whether it's a bug.

If you need some additional data, just let me know.
Thanks
Terence

uname -a
Linux RHEL63TEMP3942 2.6.32-279.el6.x86_64 #1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
[WFUser@RHEL63TEMP3942 tmp]$

[WFUser@RHEL63TEMP3942 tmp]$ ls -Asl  /tmp |sort -k11 -k7M -k8n -k9,10
total 76
0 -rw-------. 1 root   root      0 Nov  9 15:06 yum.log
4 -r--r--r--. 1 root   root     11 Nov  9 17:37 .X0-lock
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 .esd-500
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 keyring-nQ6lMb
4 drwx------. 2 gdm    gdm    4096 Nov  9 17:39 orbit-gdm
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 pulse-g9SlRO3UEqGg
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 virtual-WFUser.AVmQkN
4 drwx------. 2 gdm    gdm    4096 Nov  9 17:40 pulse-Jkx9hhtHj4dy
4 drwx------. 2 WFUser WFUser 4096 Nov  9 18:20 orbit-WFUser
4 drwxrwxrwt. 2 root   root   4096 Nov  9 18:35 .ICE-unix
4 drwx------. 2 root   root   4096 Nov  9 18:35 keyring-kjLYun
4 drwx------. 2 root   root   4096 Nov  9 18:35 orbit-root
4 drwx------. 2 root   root   4096 Nov  9 18:35 pulse-TSaTZvcbd1kc
4 drwx------. 2 root   root   4096 Nov  9 18:35 ssh-BRSEI10523
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 -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:15 .tc4
4 -rw-rw-r--. 1 WFUser WFUser    5 Nov 16 18:18 .tc3

[WFUser@RHEL63TEMP3942 tmp]$ ls -Asl  /tmp |sort -k11d -k7M -k8n -k9,10
total 76
0 -rw-------. 1 root   root      0 Nov  9 15:06 yum.log
4 -r--r--r--. 1 root   root     11 Nov  9 17:37 .X0-lock
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 .esd-500
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 keyring-nQ6lMb
4 drwx------. 2 gdm    gdm    4096 Nov  9 17:39 orbit-gdm
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 pulse-g9SlRO3UEqGg
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 virtual-WFUser.AVmQkN
4 drwx------. 2 gdm    gdm    4096 Nov  9 17:40 pulse-Jkx9hhtHj4dy
4 drwx------. 2 WFUser WFUser 4096 Nov  9 18:20 orbit-WFUser
4 drwxrwxrwt. 2 root   root   4096 Nov  9 18:35 .ICE-unix
4 drwx------. 2 root   root   4096 Nov  9 18:35 keyring-kjLYun
4 drwx------. 2 root   root   4096 Nov  9 18:35 orbit-root
4 drwx------. 2 root   root   4096 Nov  9 18:35 pulse-TSaTZvcbd1kc
4 drwx------. 2 root   root   4096 Nov  9 18:35 ssh-BRSEI10523
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 -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:15 .tc4
4 -rw-rw-r--. 1 WFUser WFUser    5 Nov 16 18:18 .tc3
[WFUser@RHEL63TEMP3942 tmp]$

[WFUser@RHEL63TEMP3942 tmp]$ ls -Asl  /tmp |sort -r -k11d -k7M -k8n -k9,10
total 76
4 -r--r--r--. 1 root   root     11 Nov  9 18:35 .X2-lock
4 drwxrwxrwt. 2 root   root   4096 Nov  9 18:35 .X11-unix
4 drwx------. 2 root   root   4096 Nov  9 18:35 ssh-BRSEI10523
4 drwx------. 2 root   root   4096 Nov  9 18:35 pulse-TSaTZvcbd1kc
4 drwx------. 2 root   root   4096 Nov  9 18:35 orbit-root
4 drwx------. 2 root   root   4096 Nov  9 18:35 keyring-kjLYun
4 drwxrwxrwt. 2 root   root   4096 Nov  9 18:35 .ICE-unix
4 drwx------. 2 WFUser WFUser 4096 Nov  9 18:20 orbit-WFUser
4 drwx------. 2 gdm    gdm    4096 Nov  9 17:40 pulse-Jkx9hhtHj4dy
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 virtual-WFUser.AVmQkN
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 pulse-g9SlRO3UEqGg
4 drwx------. 2 gdm    gdm    4096 Nov  9 17:39 orbit-gdm
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 keyring-nQ6lMb
4 drwx------. 2 WFUser WFUser 4096 Nov  9 17:39 .esd-500
4 -r--r--r--. 1 root   root     11 Nov  9 17:37 .X0-lock
0 -rw-------. 1 root   root      0 Nov  9 15:06 yum.log
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 -rw-rw-r--. 1 WFUser WFUser    5 Nov 16 18:14 .tc2
4 -rw-rw-r--. 1 WFUser WFUser    5 Nov 16 18:14 .tc
[WFUser@RHEL63TEMP3942 tmp]$