sort MM/DD/YY in reverse chron order with -k...

sort MM/DD/YY in reverse chron order with -k...

Post by Robert Kat » Wed, 12 Mar 2003 16:33:44



[ . . . ]

Quote:

> My goal is to sort lines like this:
> tape.0099          0 KB  08/20/02 03/03/03 01/17/03
> in reverse chronological order using only the last (6th) column.

> I figured substring matches on the string 01/17/03 would work:
>  sort -r -k 6.7,6.8n -k 6.0,6.1n tapefile

In `sort -kF.C', the sort character, offset, `C', can't be 0.
When counting characters, use the `-b' flag to ignore blanks.
Try this:

     sort -br -k6.7,6.8 -k6.1,6.5

Quote:

> but it sorts only by the last field (year)

[ . . . ]

Quote:> P.S.  Here is an example of what I am trying to sort:
> tape.0001          0 KB  08/20/02 03/03/03 03/03/03
> tape.0002         55 GB  08/20/02 11/25/02 12/09/02
> tape.0009         83 GB  08/21/02 02/28/03 03/10/03
> tape.0010          0 KB  08/26/02 02/28/03 02/28/03  
> tape.0011         57 GB  08/26/02 02/22/03 03/03/03
> tape.0012         93 GB  09/09/02 09/09/02 09/28/02
> tape.0013        125 GB  09/09/02 09/09/02 09/30/02
> tape.0021         95 GB  10/07/02 02/03/03 02/23/03
> tape.0022         49 GB  10/18/02 10/18/02 12/07/02
> tape.0023         67 GB  10/18/02 01/22/03 02/03/03
> tape.0024         49 GB  10/18/02 01/22/03 02/03/03
> tape.0027         94 GB  11/25/02 01/28/03 02/10/03
> tape.0028         23 GB  11/25/02 01/28/03 02/10/03
> tape.0029        143 GB  11/25/02 11/25/02 12/09/02
> tape.0030         98 GB  12/20/02 02/03/03 02/17/03
> tape.0031         45 GB  12/20/02 02/03/03 02/17/03
> tape.0032        121 GB  12/20/02 02/10/03 03/02/03
> tape.0033         59 GB  12/23/02 12/23/02 01/06/03

--
Regards,

---Robert

 
 
 

sort MM/DD/YY in reverse chron order with -k...

Post by Juergen Hec » Wed, 12 Mar 2003 21:55:23



> Hello,

> I must admit I have always had problems with the sort command when
> trying to sort multiple fields - I have been reading the man page over
> and over and not getting what I want so am wondering what I am
> misunderstanding/doing wrong.

> My goal is to sort lines like this:
> tape.0099          0 KB  08/20/02 03/03/03 01/17/03
> in reverse chronological order using only the last (6th) column.

> I figured substring matches on the string 01/17/03 would work:
>  sort -r -k 6.7,6.8n -k 6.0,6.1n tapefile

> but it sorts only by the last field (year)

> It works when I replace the / with spaces and treat each part of the
> date as a separate field but it is ugly (why should I have to remove
> the slashes -  I don't want sed at all):
> sed 's# \([0-9][0-9]\)/\([0-9][0-9]\)/\([0-9][0-9]\)     # \1 \2 \3 #'
> tapefile | sort  -k8rn -k6rn -k7rn

> So what am I getting wrong with the sort command?  Better code or
> pointers to what I am missing/misunderstanding would be greatly
> appreciated.

What about:

sort -t'/' -k7rn -k5.4rn -k6rn tapefile

Regards
Juergen

- Show quoted text -

Quote:> P.S.  Here is an example of what I am trying to sort:
> tape.0001          0 KB  08/20/02 03/03/03 03/03/03
> tape.0002         55 GB  08/20/02 11/25/02 12/09/02
> tape.0009         83 GB  08/21/02 02/28/03 03/10/03
> tape.0010          0 KB  08/26/02 02/28/03 02/28/03
> tape.0011         57 GB  08/26/02 02/22/03 03/03/03
> tape.0012         93 GB  09/09/02 09/09/02 09/28/02
> tape.0013        125 GB  09/09/02 09/09/02 09/30/02
> tape.0021         95 GB  10/07/02 02/03/03 02/23/03
> tape.0022         49 GB  10/18/02 10/18/02 12/07/02
> tape.0023         67 GB  10/18/02 01/22/03 02/03/03
> tape.0024         49 GB  10/18/02 01/22/03 02/03/03
> tape.0027         94 GB  11/25/02 01/28/03 02/10/03
> tape.0028         23 GB  11/25/02 01/28/03 02/10/03
> tape.0029        143 GB  11/25/02 11/25/02 12/09/02
> tape.0030         98 GB  12/20/02 02/03/03 02/17/03
> tape.0031         45 GB  12/20/02 02/03/03 02/17/03
> tape.0032        121 GB  12/20/02 02/10/03 03/02/03
> tape.0033         59 GB  12/23/02 12/23/02 01/06/03


 
 
 

sort MM/DD/YY in reverse chron order with -k...

Post by Juergen Hec » Thu, 13 Mar 2003 00:44:54



[snip]


> >sort -t'/' -k7rn -k5.4rn -k6rn tapefile

> Hello Juergen,

> This would be ideal accept how do I would still need a substring-sort
> on the month field.   That is because the "-t'/'" will make the "Month
> field" now contain "03 01" since the field is now split by "/".
> So the line below would be parsed so that
> tape....08 = field1, 20 = field2, 02 03 = field3,  03=field4, 03 01 =
> field5, 17 = field6, and 03 = field7.

> Also I see in the last try/example I posted, I left off the day.  So
> the type of lines I was trying also included:

> sort -r -k 6.7,6.8n -k 6.0,6.1n -k6.3,6.4n tapefile
> (sort first by Year then Month, then Day)

[snip]

field5=03 01
       ^^^^^
Pos.:  12345

sort -nr -t'/' -k7 -k5.4,5.5 -k6 tapefile

Using option -k the first position is 1 (one), not 0 (zero)

Regards,
Juergen

 
 
 

sort MM/DD/YY in reverse chron order with -k...

Post by laura fairhe » Thu, 13 Mar 2003 14:01:54




>>In `sort -kF.C', the sort character, offset, `C', can't be 0.
>>When counting characters, use the `-b' flag to ignore blanks.
>>Try this:

>>     sort -br -k6.7,6.8 -k6.1,6.5

>sort -br -k 6.7,6.8n -k 6.1,6.5n tapefile

>Well I a still am not sure why the -b helps, but it definitely made it
>better.  And the idea of bridging the MM and DD fields with one
>-k6.1,6.5 is nice - I like things concise.

>However the command above that i used, gives the following mixed up
>file.   Some tapes are ftape and others b or ntape but the problem is
>that last field - a few 99's on top, some in the middle, etc.
>Everything is scattered.  Any ideas what I am doing wrong?

>thanks,

>Adam

>"sort -br -k 6.7,6.8n -k 6.1,6.5n tapefile" gives this file:

I can't see why your 'sort' is giving you this behaviour
however you need more than 2 sort keys '6.1,6.5n' is
not a number, so specifying the numberic fields instead;

sort -br -k 6.7,6.8n -k 6.1,6.2n -k 6.4,6.5n

works, also why bother with 'n' on every field since every
field is to be sorted as numeric you can use the global
option;

sort -brn -k 6.7,6.8 -k 6.1,6.2 -k 6.4,6.5

bestwishes
laura

--
alt.fan.madonna |news, interviews, discussion, writings
                |chat, exchange merchandise, meet fans....
                |Get into the groove baby you've got to... check us out!

 
 
 

sort MM/DD/YY in reverse chron order with -k...

Post by Robert Kat » Fri, 14 Mar 2003 10:50:26





>>>In `sort -kF.C', the sort character, offset, `C', can't be 0.
>>>When counting characters, use the `-b' flag to ignore blanks.
>>>Try this:

>>>    sort -br -k6.7,6.8 -k6.1,6.5

>>sort -br -k 6.7,6.8n -k 6.1,6.5n tapefile

>>Well I a still am not sure why the -b helps, but it definitely made it
>>better.  And the idea of bridging the MM and DD fields with one
>>-k6.1,6.5 is nice - I like things concise.

>>However the command above that i used, gives the following mixed up
>>file.   Some tapes are ftape and others b or ntape but the problem is
>>that last field - a few 99's on top, some in the middle, etc.
>>Everything is scattered.  Any ideas what I am doing wrong?

Yes, why are you using `n'.  That's not what suggestion was.
Look above

     sort -br -k6.7,6.8 -k6.1,6.5

As Laura pointed out, 6.1 to 6.5 is not numeric, but you still need only two
sort keys.  Of course, you'll have to take into account that 99 was last, or
several, centuries ago, and not something that yas yet to take place `100k +
96' years from now, where k = 0, 1, 2, ...

- Show quoted text -

Quote:

>>thanks,

>>Adam

>>"sort -br -k 6.7,6.8n -k 6.1,6.5n tapefile" gives this file:

> I can't see why your 'sort' is giving you this behaviour
> however you need more than 2 sort keys '6.1,6.5n' is
> not a number, so specifying the numberic fields instead;

> sort -br -k 6.7,6.8n -k 6.1,6.2n -k 6.4,6.5n

> works, also why bother with 'n' on every field since every
> field is to be sorted as numeric you can use the global
> option;

> sort -brn -k 6.7,6.8 -k 6.1,6.2 -k 6.4,6.5

sort -br -k6.7,6.8 -k6.1,6.5

--
Regards,

---Robert

 
 
 

1. Changing all date fields from mm/dd/yy to dd/mm/yy

Please, I'm looking for a way to change all date fields in a specified
file, like this:

solaris> cat file

05/23/06      03/12/06

07/10/06                   11/12/06           09/20/06

      03/11/06

I need change all date field from mm/dd/yy to dd/mm/yy, like this:

solaris> ./script < cat file

23/05/06        12/03/06

10/07/06                 12/11/06             20/09/06

       11/03/06

Thanks !

2. Mounting Local Solaris FS from NT 4.0?

3. Sort by First Date Field (MM/DD/YY)

4. Networking Problem.

5. Files modified since yy/mm/dd hh:mm

6. printer page accouting in sol7

7. HELP: C prog to get mm/dd/yy format

8. afterstep and xfree 3.3

9. How to convert dd/mm/yy to unix epoch time?

10. How to translate date in dd/mm/yy format

11. Need f77 idate(mm,dd,yy) function

12. How to convert Posix date to YY/MM/DD ?

13. How to read file modification date (mm-dd-yy) in Korn