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?

You can use the common "decorate, sort, undecorate" pattern:

:%s!^\(\d\d\)/\(\d\d\)/\(\d\d\d\d\)!\3\2\1&
:%sort
:%s/^........

This makes the data look like

2007040101/04/2007, field...

putting it in YYYYMMDD format, and then sorts it, before removing those lines. If not all your lines match that pattern ("MM/DD/YYYY"), you may have to to a small bit more work to identify the lines you want to manipulate.

-tim




Reply via email to