striker wrote:
I have a text file in the format:
01/04/2007,field1,field2,field3
01/03/2007,field1,field2,field3
12/30/2006,field1,field2,field3
etc...
I need to sort by date, but the new dates in 2007 are placed first in
the sort algorithm. How can I sort by the entire date in the format above?
TIA,
Kevin
IIUC, this calls for a "decorate - operate - undecorate" process:
1,$s/^\d\d\/\d\d/\(\d\d\d\d\).*$/\1:\0/
1,$sort
1,$s/^\d*://
The first line adds the year in front, so that the lines appear as
yyyy:mm/dd/yyyy,etc.
The second line sorts the lines. Since yyyy:mm/dd are now in front, they will
be sorted by date.
The third line removes what the first line had added.
Best regards,
Tony.