Good day -
I would like to sort a file like this (colon as separator):
[tt]
ddd:260:a
bbb:200:a
ddd:27:a
bbb:30:a
[/tt]
I'd like the results to be ordered by field 1, then by field 2 numerically, so that the result is:
[tt]
bbb:30:a
bbb:200:a
ddd:27:a
ddd:260:a
[/tt]
If I'm reading the man page right, the correct command should be:
[tt]
sort -t : -k 1,2n <file>
[/tt]
but alas, the output is not what I want:
[tt]
bbb:200:a
bbb:30:a
ddd:260:a
ddd:27:a
[/tt]
(that is, it's as if the "n" type of field 2 is being ignored). Oddly, this command:
[tt]
sort -t : -k 2,2n <file>
[/tt]
does correctly sort by field 2 numerically (but of course doesn't take field 1 into consideration).
I've tried both versions of sort, and variants of the -t argument (e.g., [tt]-t:, -t ':', -t\:[/tt]) to no avail. Suggestions, workarounds?
-- GD
I would like to sort a file like this (colon as separator):
[tt]
ddd:260:a
bbb:200:a
ddd:27:a
bbb:30:a
[/tt]
I'd like the results to be ordered by field 1, then by field 2 numerically, so that the result is:
[tt]
bbb:30:a
bbb:200:a
ddd:27:a
ddd:260:a
[/tt]
If I'm reading the man page right, the correct command should be:
[tt]
sort -t : -k 1,2n <file>
[/tt]
but alas, the output is not what I want:
[tt]
bbb:200:a
bbb:30:a
ddd:260:a
ddd:27:a
[/tt]
(that is, it's as if the "n" type of field 2 is being ignored). Oddly, this command:
[tt]
sort -t : -k 2,2n <file>
[/tt]
does correctly sort by field 2 numerically (but of course doesn't take field 1 into consideration).
I've tried both versions of sort, and variants of the -t argument (e.g., [tt]-t:, -t ':', -t\:[/tt]) to no avail. Suggestions, workarounds?
-- GD