Bug 137485 - sort -M doesn't honor month sort
Summary: sort -M doesn't honor month sort
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: coreutils   
(Show other bugs)
Version: 3.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Tim Waugh
QA Contact:
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-10-28 19:31 UTC by Jim Salter
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-01-12 11:34:16 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

Description Jim Salter 2004-10-28 19:31:08 UTC
Description of problem:

sort -M doesn't honor month sorting

Version-Release number of selected component (if applicable):

coreutils-4.5.3-26

How reproducible:

create a file with a myriad of months and days and years:

[Fri Oct 01 00:01:34 2003]
[Fri Oct 12 00:01:34 2004]
[Mon Sep 20 12:58:07 2004]

Steps to Reproduce:
1. create a sort command to sort by year, month and then day
2. run the command: LC_ALL=C sort -n -k 5 -M -k 2 -n -k 3 sortfile
3.
  
Actual results:

results are:

[Fri Oct 01 00:01:34 2003]
[Fri Oct 12 00:01:34 2004]
[Mon Sep 20 12:58:07 2004]

Expected results:

[Fri Oct 01 00:01:34 2003]
[Mon Sep 20 12:58:07 2004]
[Fri Oct 12 00:01:34 2004]

Additional info:

Comment 1 Tim Waugh 2004-10-29 12:33:16 UTC
Thanks for the report.  The fix for this issue will be included with
any future coreutils update for Red Hat Enterprise Linux 3.

Comment 2 Karel Zak 2005-01-12 11:27:06 UTC
This is not a bug. Please, read man sort. The format of key position
setting is

 -k F[.C][OPTS]   

where 'F' is field number and 'C' char position in field and OPTS are
key options.

It means:

 -k 2M     if you want to sort second field as months

if you define separate -M the sort use it as global options and _each_
key is used as month. It means your setting "-n -k 5 -M -k 2" define
two keys and each is marked as month and numeric too. The numeric is
evaluated first in code so month in your setting is ignored.

The solution:

$ LC_ALL=C sort -k 5n -k 2M -k 3n ~/s
[Fri Oct 01 00:01:34 2003]
[Mon Sep 20 12:58:07 2004]
[Fri Oct 12 00:01:34 2004]



Comment 3 Tim Waugh 2005-01-12 11:34:16 UTC
Now that I re-read this, the fix I referred to in comment #1 is for -M
when used in UTF-8 encodings, and I see that you are using the C locale.

Closing due to comment #2 (thanks Karel).


Note You need to log in before you can comment on or make changes to this bug.