LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2012, 02:15 AM   #1
smilemukul
Member
 
Registered: Jun 2009
Distribution: Redhat,CentOS,Ubuntu,Puppet
Posts: 292

Rep: Reputation: 34
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.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-17-2012, 02:33 AM   #2
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Solution is on this page:

http://www.cyberciti.biz/faq/linux-u...g-sortcommand/
 
Old 02-20-2012, 09:47 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,937

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by Satyaveer Arya View Post
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.
 
3 members found this post helpful.
Old 02-20-2012, 03:34 PM   #4
satyadev75
LQ Newbie
 
Registered: Nov 2010
Location: Chennai
Posts: 21

Rep: Reputation: 0
$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
 
Old 02-20-2012, 04:14 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,937

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by satyadev75 View Post
$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?
 
Old 02-21-2012, 09:34 AM   #6
satyadev75
LQ Newbie
 
Registered: Nov 2010
Location: Chennai
Posts: 21

Rep: Reputation: 0
sorry for duplicate reply. TBOne already sent. I didn't see it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting find by date casperdaghost Linux - Newbie 4 02-06-2012 08:53 PM
[SOLVED] sorting of files and creating a loop to process them date wise umix Linux - Newbie 8 12-03-2011 05:12 AM
sorting date secondchanti Linux - Newbie 3 08-18-2010 09:55 PM
Sorting photos into folders based on exif date SuperJediWombat! Programming 7 05-16-2009 07:53 PM
Sorting files by time / date. TheRealDeal Linux - General 2 08-06-2006 10:35 PM


All times are GMT -5. The time now is 04:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration