I'd expect it to recognise the field delimiter, skipping field 1 and then sorting numerically on the second field (i.e. to put the longest time first and the shortest last). Any ideas please? Is the ":" in this field causing an issue?
I've proven it is recognising the second field as the sort key by changing to a dictionary-based sort too:
This produces the desired output against this subset of data, but when I run it against the 'live' data (of much larger volume) it isn't any use as it will start with all times beginning with '9' first and then in descending order, it has to be a numeric-based sort ultimately.
Thanks for the uber-fast reply Krish. I looked at the key definition thing (k switch) but it didn't seem to to work either. Using what you gave does the right thing, only, when I transpose that command to use on my live data, it doesn't. Here's an example (first 10 lines out of the newly sorted file):
@ripat
Nope doesn't work - check the second column when having the ":" as delimeter. It only sorts the 1st number in front of the 1st ":".
@miwinter
Hm, I tested it with mawk on Debian Linux and on AIX with awk and no duplicate output. Not sure what you have to add to supress the duplicates... if you find no option to tell it awk, maybe pipe it into "uniq" at the end.
And one more...
Forgot about that you can use more than one Field Separator - so here a more compact version (ok, some cheating on the delimiters with sed in the end):
Option -s did the trick! Found solution by reading this man page:
Finally, as a last resort when all keys compare equal (or if no
ordering options were specified at all), `sort' compares the entire
lines. The last resort comparison honors the `-r' global option. The
`-s' (stable) option disables this last-resort comparison so that lines
in which all fields compare equal are left in their original relative
order. If no fields or global options are specified, `-s' has no
effect.
If you split on the colons as well, sort should work. (We assume you don't really require a stable sort; if two lines have exactly the same sort key, their order should not matter; correct?) Did you try the awk script I posted before?
Sorry era, yep, I have gone with that solution and it looks to be working a dream on my entire live data (about 43,000 rows). Thanks very much to all who have contributed in this thread, your help is much appreciated. I thought I was going mad when I saw the odd behaviour we've witnessed with sort in AIX here!