Hi,
My log file is something like this.
(08/04/2009 00:27:42.179)(:) aaaaaaaaaaaa
(08/04/2009 00:27:42.181)(:) bbbbbbbbbbbbbbbb
(08/04/2009 01:00:42.713)(:) cd cdc d ddddsksjdkssksksj
(08/04/2009 01:02:42.716)(:) raarrarararararara
(08/04/2009 01:07:43.036)(:ERROR) Port ddedededetails
(08/04/2009 01:08:43.039)(:) No data found
Suppose current time is 08/04/2009 01:10:45
I wanto to grep for the data last hour data. Currently for getting today's data i am using
`date '+ %m/%d'`
Can someone help me with the modification of this command to get the previous hour data?
---------- Post updated at 02:33 AM ---------- Previous update was at 02:11 AM ----------
I want the data starting with 08/04/2009 00
try...
grep $(date '+ ( %m/%d/%Y %H') < file
protocomm, i am getting the current hour data with that..i need previous hour data.
for example, current time is 06:48. I need the data from 05:00 to 05:59
Id recommend using this as a script:
The only catch is if it happens to be between midnight and 01:00 this won't work. If you need this functionality let me know and I'll see if I can figure something out.
bash code:
bash-3.00$ genexpression()
> {
> stime=`date '+ %H'`
> stime=`expr $stime \- 1`
> if (( $stime < 10 ))
> then
> stime=0${stime}
> fi
> express=\$\\\(`date '+%m/%d/%Y'`\ $stime
> }
bash-3.00$ genexpression
bash-3.00$ egrep "$express" testfile
---------- Post updated at 04:15 AM ---------- Previous update was at 04:08 AM ----------
Now that I think about it you can probably replace the while thing with this if you manually typing in the time is ok:
> express=\$\\\(`date '+%m/%d/%Y'`\ "hour you want to filter"
i can't add that manually ..need to cron the script
And the $express from the above script seems to be returing null.
in the last line try:
export express=\$\\\(`date '+%m/%d/%Y'`\ $stime
the result is not showing the 0 before the hrs. I mean it is coming as 08/03/2009 9 instead of 08/03/2009 09
Please help.
---------- Post updated at 06:56 AM ---------- Previous update was at 06:55 AM ----------
And i need to run the script through out the day.
Are you using the entire function or just the last line? Also what shell are you using? I was using bash when I wrote that function.
Sorry i was using ksh as my entire script is in ksh. And i did run the total function...