help searching log file with dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help searching log file with dates
# 1  
Old 08-22-2005
help searching log file with dates

Im tyring to create a script that will show me any lines in a file with todays date and yesterdays, the date format in the file is as follows



----- amqxfdcx.c : 728 --------------------------------------------------------
07/12/05 09:53:20
AMQ6109: An internal WebSphere MQ error has occurred.

EXPLANATION:
An error has been detected, and the WebSphere MQ error recording routine has bee
n
called.
ACTION:
Use the standard facilities supplied with your system to record the problem
identifier, and to save the generated output files. Contact your IBM support
center. Do not discard these files until the problem has been resolved.

It would be nice if I could capture the whole message, not sure if that is possible, but at least if the script could print out any times todays date and yesterdays is in written in the log
# 2  
Old 08-23-2005
This Ruby program will do it:
Code:
today = Time.now.strftime('%m/%d/%y')
yesterday = (Time.now - 24*60*60).strftime('%m/%d/%y')

array=ARGF.read.split(%r!(^\d+/\d+/\d+)!)

(1..array.size).step(2){ |i|
  if (array[i] == today) or (array[i] == yesterday)
    print array[i] + array[i+1]
  end
}

# 3  
Old 08-23-2005
Quote:
Originally Posted by futurelet
This Ruby program will do it:
Code:
today = Time.now.strftime('%m/%d/%y')
yesterday = (Time.now - 24*60*60).strftime('%m/%d/%y')

array=ARGF.read.split(%r!(^\d+/\d+/\d+)!)

(1..array.size).step(2){ |i|
  if (array[i] == today) or (array[i] == yesterday)
    print array[i] + array[i+1]
  end
}

what shell is this written in?
# 4  
Old 08-23-2005
It's written in the Ruby programming language. Think of it as a much more powerful replacement for Awk. I'd recommend installing it if you don't already have it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help searching for dates - Oracle ALERT log

Hi, I am searching for some specific string in an Oracle DB alert log and then possibly print the latest date string that I can find that the error happen. I can't work out how to search for date strings more so searching in some specific direction, i.e backward or forward. At the moment,... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Shell Programming and Scripting

Grepping only dates from a log file

Hi All, I have a log file where every line contains a date and some other data, i want to grep only the date from every line to a different file. Please help how to get this. Thanks in advance !! (25 Replies)
Discussion started by: nanz143
25 Replies

3. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

4. Shell Programming and Scripting

How to processing the log file within certain dates based on the file name

Hi I am working on the script parsing specific message "TEST" from multiple file. The log file name looks like: N3.2009-11-26-03-05-02.console.log.tar.gz N4.2009-11-29-00-25-03.console.log.tar.gz N6.2009-12-01-10-05-02.console.log.tar.gz I am using the following command: zgrep -a --text... (1 Reply)
Discussion started by: shyork2001
1 Replies

5. Shell Programming and Scripting

Searching for a string in a log file with little movement

I have a script which tails a log file and if it finds certain strings in the data tailed it sends an email, basically like this: tail -f logfile > tmp.file & sleep 10 kill $! STRING=$(grep -c "string" tmp.file) && echo $STRING | mailx -s "Warning.." admin@123.com When the string is... (10 Replies)
Discussion started by: Moxy
10 Replies

6. Shell Programming and Scripting

find log file between two dates

Dear All, Please can you help me to crack this query? If the log files for the task above all had a naming convention of myoutput_YearMonthDay.log (i.e. myoutput_20060215) How would you find only those log files created between the 10th and the 20th of each month going back the last 365 days.... (1 Reply)
Discussion started by: justin_mca
1 Replies

7. Shell Programming and Scripting

grep a log file to filter previous dates

Hi, I have problem of filtering a log file from my perl script. #cat /data/pinpe.csv_20070731 | nawk -v FS=, '{print $1','$18','$22','$26}' | grep -w 100 | grep -w 1 | nawk '{print $4}' Below is the output: 2009-06-16 2009-01-29 2009-06-02 2008-03-05 2007-08-05 2007-09-24... (5 Replies)
Discussion started by: pinpe
5 Replies

8. Shell Programming and Scripting

grep a log file between 2 dates

Hi Currently I can grep a log file with the following command: $results = `grep -A 2 '^$date.$time.*' $log`; and the following arguments: $date = 2007/04/25 $time = 16:07 Log example: 2007/04/25 16:07:12.145701 2007/05/25 14:07:12.145701 2007/05/25 17:07:12.145701 2007/06/25... (37 Replies)
Discussion started by: Epiphone
37 Replies

9. Linux

Searching for gaps in huge (2.2G) log file?

I've got a 2.2 Gig syslog file from our Cisco firewall appliance. The problem is that we've been seeing gaps in the syslog for anywhere from 10 minutes to 2 hours. Currently I've just been using 'less' and paging through the file to see if I can find any noticeable gaps. Obviously this isn't the... (3 Replies)
Discussion started by: deckard
3 Replies

10. Shell Programming and Scripting

Searching between dates

Hello people, I have a file containing dated entries. Is there a way to search between dates? for example, in a file <file.text> with entries 04-jul-2005 login: pty0 xxxxxx xxxxxx 09-jul-2005 logout pty34 xxxxxx xxxxxx 11-aug-2005 arp port17 xxxxxx xxxxxx 30-sep-2005... (9 Replies)
Discussion started by: Khoomfire
9 Replies
Login or Register to Ask a Question