How to sort by date in descending order

Dave Cross davorg at gmail.com
Fri Feb 26 16:33:00 UTC 2010


On 26 February 2010 13:40, Roberto Ragusa <mail at robertoragusa.it> wrote:
> Richard Cahilig wrote:
>> Hi,
>>
>> Guys I need your help, I have a text file which contains these data
>> below, and I want to sort it by date in descending order. I tried to use
>> sort -rn command but it gives me different output. I know I missing
>> something but I just can't figure it out.
>>
>> files     03-Sep-2009
> [...]
>> files     07-Jul-2006
>>
>> Your help is very much appreciated. Thanks.
>
> while read a b; do s1=`date --date "$b" +%s`; echo $s1 $a $b;done <yourfile.txt | sort -nr

Very nice. Just one small addition - pass the output through cut to
get back to the original data format:

while read a b; do s1=`date --date "$b" +%s`; echo $s1 $a $b;done
<yourfile.txt | sort -nr | cut -f 2- -d ' '


Dave...


More information about the users mailing list