bug-coreutils
[Top][All Lists]
Advanced

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

bug#10019: sort options -Mn are incompatible


From: Bob Proulx
Subject: bug#10019: sort options -Mn are incompatible
Date: Fri, 11 Nov 2011 11:02:37 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

tags 10019 + moreinfo notabug
thanks

Lars Noodén wrote:
> Since the sort options -M and -n are incompatible, there appears to
> be no easy way to sort log files.

Unfortunately your bug report doesn't include enough information to
understand what you are reporting.  It does not make sense that you
would have a sort field that is *both* a month *and* numeric and by
which you would want to sort by *both* on the same field.  Of course
numerically is not the same as by month and by month is not the same
as numerically.  They cannot be "compatible" by definition.

You did not include a small example to illustrate what you wanted to
do.  Without that I can only guess at things.  Also the program
version is important too.  Please include that information in the bug
report.

Perhaps you are actually trying to sort *different* fields using
different sort methods?  If so then perhaps you are not aware of the
sort -k option which is to be used when you wish to sort different
fields with different keys.  The documentation for sort -k says:

`-k POS1[,POS2]'
`--key=POS1[,POS2]'
     Specify a sort field that consists of the part of the line between
     POS1 and POS2 (or the end of the line, if POS2 is omitted),
     _inclusive_.

     Each POS has the form `F[.C][OPTS]', where F is the number of the
     field to use, and C is the number of the first character from the
     beginning of the field.  Fields and character positions are
     numbered starting with 1; a character position of zero in POS2
     indicates the field's last character.  If `.C' is omitted from
     POS1, it defaults to 1 (the beginning of the field); if omitted
     from POS2, it defaults to 0 (the end of the field).  OPTS are
     ordering options, allowing individual keys to be sorted according
     to different rules; see below for details.  Keys can span multiple
     fields.

     Example:  To sort on the second field, use `--key=2,2' (`-k 2,2').
     See below for more notes on keys and more examples.  See also the
     `--debug' option to help determine the part of the line being used
     in the sort.

If you wish to sort one field by month and one field numbered you
would specify that with different fields.  You mentioned log files so
let me propose a simple log file example.  This is off the top of my
head and perhaps wrong but should at least get you pointed in the
right direction.

  $ printf "
Nov 11 06:54:44 foo did something
Nov 11 06:55:25 bar did another something else
Nov 11 10:53:38 zoo reported
Feb  7 11:23:43 zoo reported
" | sort -s -k1M,1 -k2n,2 -k3,3 -k4,4

Feb  7 11:23:43 zoo reported
Nov 11 06:54:44 foo did something
Nov 11 06:55:25 bar did another something else
Nov 11 10:53:38 zoo reported

Bob





reply via email to

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