Checking Log Entries for Specific Time Duration
Hi Shell Script Gurus!
I have a log file. Each line starts with a date/time-stamp such as: Code:
[30 Jan 2012 22:10:15,22] blah! blah Code:
$ echo $ago Code:
$ cat data.log | awk -v whence="$ago" '{if($0 ~ whence){found=1;}if(found==1){print $0}}' What I want is if Hours 22 if not there but still it should check for newer entries, such as these ones: Code:
[30 Jan 2012 23:00:15,20] blah! blah Code:
ago=`date "+%d %b %Y %H" -d "$1 hours ago"` So that we can say: Code:
script.sh 4 Note: We are no interested in the Minutes:Seconds fields. Only Hours is important for a given date/time. The above "date" command is very helpful if 4 hours ago it was yesterday's date. But if the Hours value is exactly not matched then the newer entries are skipped which is something undesirable (the "awk" command as given above). Well, something similar to this scenario I have done before using "awk" but my head is not able to recall how.:scratch: |
In awk, the selection criterion would become > the $ago value and you wouldn't need the found flag.
But be careful. As you define the problem, feb 01 (today) wouldn't select correctly. So maybe you change "ago" to contain Quote:
$3 plus $2 transformed into 01, 02 .. 12 from Jan, Feb .. Dec plus $1 plus left($3,2). I leave it to you work it out. OK |
Quote:
Well, I did not get your solution even though I read it twice or thrice. If the date part would not be a problem then I would simply compare the Hours field and get the work done as I have done before. But in the present scenario the Date part is important when it changes from yesterday's to today's. |
All times are GMT -5. The time now is 05:24 AM. |