This service will be undergoing maintenance at 20:00 UTC, 2017-04-03. It is expected to last about 30 minutes
Bug 137485 - sort -M doesn't honor month sort
sort -M doesn't honor month sort
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: coreutils (Show other bugs)
3.0
All Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-10-28 15:31 EDT by Jim Salter
Modified: 2007-11-30 17:07 EST (History)
0 users

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


Attachments (Terms of Use)

  None (edit)
Description Jim Salter 2004-10-28 15:31:08 EDT
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 08:33:16 EDT
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 06:27:06 EST
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 06:34:16 EST
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.