Re: sorting dates in ksh
Posted in 2004
Jonathan Leffler wrote: > > So, some people spent the whole of the run-up to Y2K in a coma? Use 4 > digits for the year. Please! :-) clearly !-) > It isn't clear which order the fields within the date are ordered; > unless the order is year, month, day, it is going to be difficult to > sort that data without pre-processing it. > > Sort assumes that all the fields in a sort are separated by the same > delimiter. If you use white space as the delimiter, the second field > has to be self-sorting into date order. If, as I suspect, the order > is month, day, year within the field, then you have big problems - you > can't sort by sub-fields. not true - sort can be told to use sub-positions as long as they are fixed so, if the order of the fields is MM/DD/YY (blessed to have fixed with digits) then it would be: sort -b +1.3 -1.5 +1.0 -1.2 +1.6 -1.8 or something like that note that the +POS -POS syntax is considered obsolete, and has been supersceded by the -k option which looks like -k POS,POS. With the -k style, POS indexes are counted as starting at one instead of the traditional zero, so add 1 to all the numbers given above I'm also a bit suspicios that my final -1.8 perhaps should be -2 but I'm not feeling inclined to test :-)