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:
Thanks for the report. The fix for this issue will be included with any future coreutils update for Red Hat Enterprise Linux 3.
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]
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).