-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Dirk-Jan Faber on 6/4/2008 6:29 AM: | Hello, | | When trying to sort input that has spaces in it I am getting unexpected behaviour. When using the inputfile:
Not a bug. Your problem is that you aren't specifying the correct keys. | | Trying to sort this input gives: | $ cat in.txt | sort -t' ' -n -k1n -k2n -k3n Useless use of cat. | | I would have expected the output to be different, the "9 5 10" line ought to be before the line starting with the ten. You are requesting the first key start at the first field, treated numerically, and extending through the end of the line. What you wanted was to specify the first key as numeric, but ending at the first field. Also, since you specified -n globally, you don't need to repeat it for the keys: sort -t' ' -n -k1,1 -k2,2 -k3,3 < in.txt | This bug can be bypassed by replacing the spaces with another character like the semicolon: | $ cat in.txt | tr ' ' ':' | sort -t':' -n -k1n -k2n -k3n | tr ':' ' ' Another useless use of cat (hint - "tr ' ' ':' < in.txt" is more efficient than "cat in.txt | tr ' ' ':'"). The reason this worked around your problem is that ':' is greater than '9', but ' ' is less than '0', when the rest of the line is tacked on to the end of your sort key. | $ sort --version | sort (GNU coreutils) 6.10 Consider upgrading - the latest stable version is 6.12. - -- Don't work too hard, make some time for fun as well! Eric Blake [EMAIL PROTECTED] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkhGj6cACgkQ84KuGfSFAYB5qgCfQ5DmGRpGq1vRFknuzLJs1E5b KjIAnR9ga82tvk5ySFfzvqTnKGpsFMj2 =Jeow -----END PGP SIGNATURE----- _______________________________________________ Bug-coreutils mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-coreutils
