FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 02-26-2010, 10:59 AM
Richard Cahilig
 
Default How to sort by date in descending order

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**** 04-Nov-2009
files**** 30-Nov-2009
files**** 03-Sep-2009
files**** 04-Nov-2009
files**** 30-Nov-2009
files**** 03-Sep-2009
files**** 04-Nov-2009
files**** 30-Nov-2009

files**** 03-Sep-2009
files**** 04-Nov-2009
files**** 30-Nov-2009
files**** 06-Nov-2009
files**** 09-Nov-2009
files**** 25-Apr-2007
files**** 04-Jun-2008
files**** 25-Apr-2007
files**** 30-Nov-2007

files**** 04-Jun-2008
files**** 28-Apr-2009
files**** 24-Jul-2009
files**** 09-Nov-2009
files**** 24-Jul-2009
files**** 09-Nov-2009
files**** 28-Apr-2009
files**** 24-Jul-2009
files**** 09-Nov-2009

files**** 07-Jul-2006

Your help is very much appreciated. Thanks.
Best Regards,

Richard R. Cahilig

--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 02-26-2010, 12:40 PM
Roberto Ragusa
 
Default How to sort by date in descending order

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

--
Roberto Ragusa mail at robertoragusa.it
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 02-26-2010, 12:51 PM
Patrick O'Callaghan
 
Default How to sort by date in descending order

On Fri, 2010-02-26 at 12:59 +0100, 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.

You just told it to sort in reverse numerical order. You can't directly
do what you want with 'sort' as it has no concept of date order. However
it does a concept of 'month', so you might be able to run a pipeline of
several calls to sort, first by year, then by month and finally by day.
Left as an exercise for the reader :-)

Or look around for some Perl script which no doubt has already been
written. Google is your friend.

poc

--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 02-26-2010, 03:33 PM
Dave Cross
 
Default How to sort by date in descending order

On 26 February 2010 13:40, Roberto Ragusa <mail@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...
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 02-27-2010, 04:20 PM
Roberto Ragusa
 
Default How to sort by date in descending order

Dave Cross wrote:
> On 26 February 2010 13:40, Roberto Ragusa <mail@robertoragusa.it> wrote:
>> Richard Cahilig wrote:

>>> 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 ' '

I left that as an exercise for the reader ;-)

--
Roberto Ragusa mail at robertoragusa.it
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 02-27-2010, 10:30 PM
L
 
Default How to sort by date in descending order

On Sun, Feb 28, 2010 at 4:20 AM, Roberto Ragusa <mail@robertoragusa.it> wrote:
> Dave Cross wrote:
>> On 26 February 2010 13:40, Roberto Ragusa <mail@robertoragusa.it> wrote:
>>> Richard Cahilig wrote:
>
>>>> 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 ' '
>
> I left that as an exercise for the reader ;-)
>

this line works well too

sort -t- -k3n -k2 --sort=month yourfile.txt


> --
> * Roberto Ragusa * *mail at robertoragusa.it
> --
> users mailing list
> users@lists.fedoraproject.org
> To unsubscribe or change subscription options:
> https://admin.fedoraproject.org/mailman/listinfo/users
> Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
>



--
http://etvillage.blogspot.com/
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 

Thread Tools




All times are GMT. The time now is 04:13 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org