bug-coreutils
[Top][All Lists]
Advanced

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

Re: coreutils sort


From: Bob Proulx
Subject: Re: coreutils sort
Date: Tue, 27 Jun 2006 17:15:29 -0600
User-agent: Mutt/1.5.9i

Christian wrote:
> I've got a question about sort.  I've got a gentoo based system and I
> noticed that my usually command to sort IP addresses does not seem to work
> anymore.
> I know for sure that it doesn't work with 5.94 and 5.97.

Major changes in the coreutils 5.90 release.  See the NEWS file for
all of the details.

> This is the command:
> sort -nt. +0 -1 +1 -2 +2 -3 +3 -4

Using +NUM -NUM is obsolescent usage.  You need to start using the -k
NUM usage as required by POSIX conforming applications.  The old form
has been deprecated for many years.

> and here is the error:
> 
> sort: invalid option -- 1
> Try `sort --help' for more information.

Better yet would be to see the info documentation for significantly
more information.

  info coreutils sort

     On older systems, `sort' supports an obsolete origin-zero syntax
  `+POS1 [-POS2]' for specifying sort keys.  This obsolete behavior can
  be enabled or disabled with the `_POSIX2_VERSION' environment variable
  (*note Standards conformance::).

     Scripts intended for use on standard hosts should avoid obsolete
  syntax and should use `-k' instead.  For example, avoid `sort +2',
  since it might be interpreted as either `sort ./+2' or `sort -k 3'.  If
  your script must also run on hosts that support only the obsolete
  syntax, it can use a test like `if sort -k 1 </dev/null >/dev/null
  2>&1; then ...' to decide which syntax to use.

> I've been using that command syntax to sort IP's for several years without
> any problems until just recently.

You must have just recently upgraded to a newer version of coreutils.
Please start using the keys option to specify sort keys.  The syntax
you need is this:

  sort -n -t. -k1,1 -k2,2 -k3,3 -k4,4

You can find online standards information about sort here:

  http://www.opengroup.org/onlinepubs/009695399/utilities/sort.html

And more recent news about this change here:

  http://www.opengroup.org/austin/docs/austin_239.html

Bob




reply via email to

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