coreutils
[Top][All Lists]
Advanced

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

Re: sort's --key argument


From: Eric Blake
Subject: Re: sort's --key argument
Date: Mon, 27 Jun 2011 13:31:59 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.10

On 06/27/2011 11:10 AM, Peng Yu wrote:
> Hi,
> 
> I want to sort by the 2nd column (see the 2nd command). But it seems
> that it still sorts by the second column then by the first column.
> Does anybody know how --key works?

Yes.  Unless you specify -s/--stable, then coreutils uses a last-resort
sort, as if you had specified -k1 for selecting the entire line.  And
'sort --debug' shows this:

> $sort --key=2,2 input.txt

$ LC_ALL=C sort --debug -k2,2 input.txt
sort: using simple byte comparison
a a
 __
___
p a
 __
___

$ LC_ALL=C sort --debug -k2,2 input.txt -s
sort: using simple byte comparison
p a
 __
a a
 __

> sort (GNU coreutils) 7.4

Well, you won't get the --debug option unless you upgrade to newer
coreutils; it was added in 8.6 (latest is now 8.12).

-- 
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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