Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Solaris 8 sort bug? 1

Status
Not open for further replies.

GDameron

Programmer
Aug 8, 2003
39
US
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
 
Try this...
Code:
sort -t: +0 -1 +1n file.dat > file.sorted
 
Just what I needed, olded - much obliged. Here's your star.

GD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top