Afficher un message
Vieux 05/09/2007, 11h17   #8
moonhk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to sort field with HH:MM format ?

On 9 5 , 4 22 , "John L" <j...@lammtarra.notthisbit.fslife.co.uk>
wrote:
> "moonhk" <moon_ils...@yahoo.com.hk> wrote in messagenews:1188955488.326531.81320@o80g2000hse.go oglegroups.com...
> > I try sort without using cat, the result is not ok . It can not able
> > to sort with Time. Just for number.

>
> > sort -n -r -k 3 sort.txt
> > anny pts/106 11:05 3985530 335
> > antheaz pts/313 2:16 7438440 134
> > bettyc pts/99 1:14 7086158 291
> > berryl pts/229 1:11 1360096 307
> > benq pts/720 1:55 3801242 169
> > bellaf pts/514 1:20 5283892 270
> > aprilc pts/367 1:28 3567818 243
> > annay2 pts/94 1:31 1048696 233
> > annac pts/85 1:42 1056932 201
> > bettyk pts/145 0:50 6508572 406
> > beatrip pts/697 0:47 4669568 423
> > barrys pts/536 0:51 3305706 401

>
> OK, now you have given us an example with a double-figure
> hour (11:05) we can see it is space-padded so, if we set
> the field-separator to a character that is not in the file then
> the whole line is the first (and only) field, with the : at
> character position 24, so the hour is positions 22-23, and
> the minutes at 25-26.
>
> sort -t, -k1.22,1.23nr -k1.25,1.26nr filename
>
> but you would want to document that you are sorting by
> time because it is not obvious, and perhaps incorporate
> a check that the layout of the data does not change by
> a character or two.
>
> --
> John.- -
>
> - -


Thank. It works. Now, I am know how to using -k parameter.

sort -t, -k1.22,1.23nr -k1.25,1.26nr sort.txt
knny pts/6 11:11 985530 335
anny pts/106 11:05 3985530 335
antheaz pts/313 2:16 7438440 134
benq pts/720 1:55 3801242 169
annac pts/85 1:42 1056932 201
annay2 pts/94 1:31 1048696 233
aprilc pts/367 1:28 3567818 243
bellaf pts/514 1:20 5283892 270
bettyc pts/99 1:14 7086158 291
berryl pts/229 1:11 1360096 307
barrys pts/536 0:51 3305706 401
bettyk pts/145 0:50 6508572 406
beatrip pts/697 0:47 4669568 423


  Réponse avec citation
 
Page generated in 0,06182 seconds with 9 queries