Sorting by date and time


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sorting by date and time
# 1  
Old 07-09-2007
Sorting by date and time

Hi guys... I've been trying to do this for ages. Maybe you can help.

I have log files like the examples below and I have grepped out certain lines from the files so that I can get an idea of who is logging on and how. So now I have the information in a new file but it is now in a different order according to what was grepped first and last and I'd like to sort the data according to the date and time. Which is in the format 27-May-2007 00:43:18.28.

The sort command didn't work, has anyone got any ideas?


27-May-2007 00:43:18.28 tcp_local conversion E 9 sdf@gcvbcb.co.uk rfc822;ambury@xvxv.xcv.ie ambury@xcvxv.sds.ie /queue/queue/conversion/ZZfcbcb36o5Q5.00<00bccbc38390$92cd2fbe@Erick> mailsrv pc-146-205-47-190.cm.vtr.net ([255.47.8.146]
27-May-2007 00:43:18.28 > From: "gregeg Meskimen" <vzxvczx@xzcvz.co.uk>
27-May-2007 00:43:18.28 > X-Mailer: Microsoft Outlook, Build 10.0.6626
27-May-2007 00:43:17.93 tcp_local conversion E 2 vxcv@xcvxo.com rfc822;xghg@xhghvx.xgjx.ie vxv@xghj.ghjx.ie /queue/queue/conversion/ZZf0z5x36o5Q4.00 <0019gjgcvbf0$0@f4a04cbcb2b> mailsrv part-e489ghjg52.cpe.polou.com ([200.255.101.255])
27-May-2007 00:43:17.93 > From: "bLASD Booster" <vxcv@xvx.com>
27-May-2007 00:43:17.93 > X-Mailer: Microsoft Outlook Express %OE_VERSION%OE_SUBVERSION
# 2  
Old 07-09-2007
Write a script that uses 'cut' to split the record into fields, using '-' as the delimter.
The first field is the day of the month.
Search a table to convert the second field to a number.
/*The first four digits of the third field is the year.
The 6th through 15th digit is the time.*/
Cut the third field using space as a delimiter, and get the year and time.
Write out the year, numerical month, day and time, and the original field, then sort the output.

Last edited by jgt; 07-09-2007 at 09:31 AM.. Reason: Changed year time extraction
# 3  
Old 07-09-2007
Deleted...

Last edited by lorcan; 07-10-2007 at 12:19 AM.. Reason: Improper Solution
# 4  
Old 07-09-2007
Quote:
Originally Posted by lorcan
I have just copied a line and checked and i think it works fine

Command
Code:
sort -n file

Output

Code:
27-May-2007 00:43:17.93 > From: "bLASD Booster" <vxcv@xvx.com>
27-May-2007 00:43:17.93 tcp_local conversion E 2 vxcv@xcvxo.com rfc822;xghg@xhghvx.xgjx.ie vxv@xghj.ghjx.ie /queue/queue/conversion/ZZf0z5x36o5Q4.00 <0019gjgcvbf0$0@f4a04cbcb2b> mailsrv part-e489ghjg52.cpe.polou.com ([200.255.101.255])
27-May-2007 00:43:17.93 > X-Mailer: Microsoft Outlook Express %OE_VERSION%OE_SUBVERSION
27-May-2007 00:43:18.18 > From: "gregeg Meskimen" <vzxvczx@xzcvz.co.uk>
27-May-2007 00:43:18.28 > From: "gregeg Meskimen" <vzxvczx@xzcvz.co.uk>
27-May-2007 00:43:18.28 tcp_local conversion E 9 sdf@gcvbcb.co.uk rfc822;ambury@xvxv.xcv.ie ambury@xcvxv.sds.ie /queue/queue/conversion/ZZfcbcb36o5Q5.00<00bccbc38390$92cd2fbe@Erick> mailsrv pc-146-205-47-190.cm.vtr.net ([255.47.8.146]
27-May-2007 00:43:18.48 > From: "gregeg Meskimen" <vzxvczx@xzcvz.co.uk>

... and if you add?:
Code:
31-Dec-2007 00:15:18.20 > From: "gregeg Meskimen" <vzxvczx@xzcvz.co.uk>

# 5  
Old 07-09-2007
Deleted...

Last edited by lorcan; 07-10-2007 at 12:18 AM.. Reason: Improper
# 6  
Old 07-09-2007
Only because 31 is bigger than 27.
Try adding 31-March-2007 and 30-April-2007
# 7  
Old 07-10-2007
Sorry jgt got confused. I will modify my earlier post. Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting data file by date and time

Hello. Sorting data file by date and time with the following issues: Date is in the following format m/d/yyyy, no leading zeros Time is in the following format h:m:s AM/PM, no leading zeros Any ideas on how to sort data when the above issues? Could the date/time be converted inline to... (5 Replies)
Discussion started by: JimBurns
5 Replies

2. Shell Programming and Scripting

Sorting by date

I am trying to sort by two columns. The first column in an ID, the second is a date in the form yyyy-mm-dd. I need to sort by the ID column, then in ascending order for the date column (earliest date to most recent date compared to today). Input data: 012-abc 2012-04-25 ... (3 Replies)
Discussion started by: mollydog11
3 Replies

3. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

4. Shell Programming and Scripting

Adding time to date time in UNIX shell scipting

I needed some help in adding a duration (in seconds) to a start time (in hhmmss format) and a start date (in mmddyy format) in order to get an end date and end time. The concept of a leap year is also to be considered while incrementing the day. The code/ function that I have formed so far is as... (3 Replies)
Discussion started by: codehelp04
3 Replies

5. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

6. Shell Programming and Scripting

Date and Time sorting

Hi Guys! i have a problem of sorting column chronologically because the data i have in column is in the following format 06/Dec/2006:18:09:54 and need to be sorted in the following way (upto seconds) 06/Dec/2005:18:09:50 06/Dec/2005:18:09:51 31/Mar/2006:19:30:41 24/Oct/2006:19:16:19... (4 Replies)
Discussion started by: me_newbie
4 Replies

7. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

8. Shell Programming and Scripting

Date Sorting

Hi, I have a list of files that take on the format ABCDE_yymmdd and wish to sort them in ascending date order. I can't use the unix time stamp for the file as this could possibly be different from the date given in the file name. Does anyone know of any way this can be done using unix shell... (14 Replies)
Discussion started by: LiquidChild
14 Replies

9. UNIX for Dummies Questions & Answers

date sorting

Hi at all, I have to sort a log file on timestamp field. That's field is the third! a log file sample..... 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:23|0.3.8 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:16|0.3.8 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:20|0.3.8... (3 Replies)
Discussion started by: nmilella
3 Replies

10. UNIX for Dummies Questions & Answers

sorting on date

I have a file where dates in the form mm/dd/yyyy is the first field. How do I sort the file by the date field? Thanks, Duckman (6 Replies)
Discussion started by: Duckman
6 Replies
Login or Register to Ask a Question