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 [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
