LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sorting af file according to date (https://www.linuxquestions.org/questions/linux-newbie-8/sorting-af-file-according-to-date-929832/)

smilemukul 02-17-2012 01:15 AM

Sorting af file according to date
 
Hi,
I want to sort a file according to date but the dates are in jumbled order as,

j6dj 2012-02-16
j8nj 2012-02-17
j9nj 2012-02-16
j9xz 2012-02-17
jc2z 2012-02-17
jf30 2012-02-03
jf64 2012-02-17
jh21 2012-02-16
jh4w 2012-02-02
jh73 2012-02-17

How can I sort the file with date in sequential order.
Please assist.

Satyaveer Arya 02-17-2012 01:33 AM

Solution is on this page:

http://www.cyberciti.biz/faq/linux-u...g-sortcommand/

TB0ne 02-20-2012 08:47 AM

Quote:

Originally Posted by Satyaveer Arya (Post 4604740)

As we've asked you before Satyaveer Arya, would you PLEASE stop just posting links from a Google search? Can you try to actually provide answers?

OP, you need to read the man page on the sort command (type in "man sort" in a terminal window). Pay attention to the "-k" and the "-t" fields. Putting in "sort -k 2 <filename>" will work. Again, read the man page on the sort command if you need it reverse ordered, or need to sort more on the month fields, too.

satyadev75 02-20-2012 02:34 PM

$sort -k 2 <filename>

jh4w 2012-02-02
jf30 2012-02-03
j6dj 2012-02-16
j9nj 2012-02-16
jh21 2012-02-16
j8nj 2012-02-17
j9xz 2012-02-17
jc2z 2012-02-17
jf64 2012-02-17
jh73 2012-02-17

TB0ne 02-20-2012 03:14 PM

Quote:

Originally Posted by satyadev75 (Post 4607612)
$sort -k 2 <filename>

jh4w 2012-02-02
jf30 2012-02-03
j6dj 2012-02-16
j9nj 2012-02-16
jh21 2012-02-16
j8nj 2012-02-17
j9xz 2012-02-17
jc2z 2012-02-17
jf64 2012-02-17
jh73 2012-02-17

Yes...that's what was already posted to the OP..did you not read the previous replies?

satyadev75 02-21-2012 08:34 AM

sorry for duplicate reply. TBOne already sent. I didn't see it.


All times are GMT -5. The time now is 03:25 AM.