[Top][All Lists]

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

Re: sort -k bug

From: Bob Proulx
Subject: Re: sort -k bug
Date: Sun, 26 Oct 2003 10:16:41 -0700
User-agent: Mutt/1.3.28i

Bastian Fuchs wrote:
> maybe I don't understand the manpage, because my english isn't very
> good.  But I think that the manpage says that -k1,1 and -k1 is the
> same ... but it isn't.

Thank you for your very nice test case.  It is most appreciated.

> [bastiaf:~]% mkdir a
> [bastiaf:~]% cd a
> [bastiaf:~/a]% touch a
> [bastiaf:~/a]% ln a b
> [bastiaf:~/a]% ln a c
> [bastiaf:~/a]% ls -liA | sort -uk1
> 378446 -rw-r-----  3 bastiaf  bastiaf  0 Oct 23 21:59 a
> 378446 -rw-r-----  3 bastiaf  bastiaf  0 Oct 23 21:59 b
> 378446 -rw-r-----  3 bastiaf  bastiaf  0 Oct 23 21:59 c
> total 0
> [bastiaf:~/a]% ls -liA | sort -uk1,1
> 378446 -rw-r-----  3 bastiaf  bastiaf  0 Oct 23 21:59 a
> total 0
> [bastiaf:~/a]%

I see that same behavior.

> Manpage:
>        -k, --key=POS1[,POS2]
>               start a key at POS1, end it at POS 2 (origin 1)

The man page is really only meant as a quick reference.  It is
generated automatically from the 'sort --help' output using help2man
to create the man page.  As such it is terse by design.  The info page
contains more information and should be considered the better
reference for these things.

  info sort

`-k POS1[,POS2]'
     The recommended, POSIX, option for specifying a sort field.  The
     field consists of the part of the line between POS1 and POS2 (or
     the end of the line, if POS2 is omitted), _inclusive_.  Fields and
     character positions are numbered starting with 1.  So to sort on
     the second field, you'd use `-k 2,2' See below for more examples.

So sort -k1 starts the key at the field indicated and continues the
key to the end of line since POS2 is omitted.  In your example the
lines different at the last character.  In -k1,1 my reading of this is
that it starts the sort key at field one and stops the sort key at
field one.  The rest of the line will not be considered when sorting.
Since field one is the same the sort uniquely operation collapses
them.  But I did not actually look at the code.

As always if you have contributions or patches for the documentation
please suggest them.  Much of the documentation needs improvement and
would benefit from help.


reply via email to

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