Operating System - HP-UX
1828492 Members
2902 Online
109978 Solutions
New Discussion

Re: Sorting a file containing dates

 
SOLVED
Go to solution
Subramanian_2
Occasional Advisor

Sorting a file containing dates

Hi,
I have a file which has data in the following format:-
15-dec-1992
11-nov-1992
26-apr-1993
15-mar-1993
19-jan-1993
05-oct-1990
21-jul-1992
03-dec-1991
15-feb-1991
22-jul-1993

I want to sort the dates in the reverse chronological order.

Please help providing a sample script or command.

Regards,
Subramanian S
4 REPLIES 4
harry d brown jr
Honored Contributor
Solution

Re: Sorting a file containing dates

sort -t"-" -k3 -k2M -k1

live free or die
harry
Live Free or Die
curt larson_1
Honored Contributor

Re: Sorting a file containing dates

sort -rt"-" -k3,3n -k2,2M -k1,1n
Subramanian_2
Occasional Advisor

Re: Sorting a file containing dates

Thanks a lot mate. Good job.
Bruno Ganino
Honored Contributor

Re: Sorting a file containing dates

Harry is right !
Exist also a obsolete form of -k (+pos1, -pos2).
See here for details
http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?00+00

Bruno
Torino (Turin) +2H