?
Solved

to sort log files by date

Posted on 2008-10-25
8
Medium Priority
?
594 Views
Last Modified: 2013-12-27
Hi, I have logs files like this

<Oct 7, 2008 7:43:59 AM CDT> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.>
2008-10-07 07:44:14,106 INFO [org.springframework.core.CollectionFactory] - <JDK 1.4+ collections available>

I need to search all the lines for a particular date and then copy them to a different file. For example if I mention Oct 7, 2008 as input the above two lines are to be copied into a new file named  date_file.txt

Thanks in advance,
0
Comment
Question by:conversekid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 2000 total points
ID: 22804998
Where does the sort come into the question?

To search for a date, you just need to do

egrep "2008-10-07|Oct 7, 2008" log >date_file.txt
0
 

Author Comment

by:conversekid
ID: 22805082
Thanks...I need to get the make it varaible..example we should be able to accept any date and then search for it......
0
 

Author Comment

by:conversekid
ID: 22805111
The date in the logs will be in either of the below two formats:
<Oct 7, 2008>
 2008-10-07
We need to search for these two formats depending on the date we get as input and then copy the lines containing these lines to a different file.....
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 48

Expert Comment

by:Tintin
ID: 22805450
What format will the date be entered as?  Is this on Solaris 10?
0
 

Author Comment

by:conversekid
ID: 22805635
Its solaris 9. We can ask the user to enter the date in any particular format.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22806328
One last question, are you allowed to install any additional software?  If you can install GNU date, it would make this task much more simple.
0
 

Author Comment

by:conversekid
ID: 22806422
I really wish we could but we are not allowed to install software.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 22806609
OK, here's a script which will accept input in YYYY-MM-DD format
#!/bin/sh
DATE1=$1
year=`echo $DATE1 | cut -f1 -d-`
mon=`echo $DATE1 | cut -f2 -d-`
day=`echo $DATE1 | cut -f3 -d- | sed "s/^0//"`
 
case $mon in
1)  mon=Jan ;;
2)  mon=Feb ;;
3)  mon=Mar ;;
4)  mon=Apr ;;
5)  mon=May ;;
6)  mon=Jun ;;
7)  mon=Jul ;;
8)  mon=Aug ;;
9)  mon=Sep ;;
10) mon=Oct ;;
11) mon=Nov ;;
12) mon=Dec ;;
esac
 
DATE2="$mon $day, $year"
egrep "$DATE1|$DATE2" /some/log >date_file.txt

Open in new window

0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question