How can i grep for an hour before data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can i grep for an hour before data
# 1  
Old 08-04-2009
How can i grep for an hour before data

Hi,

My log file is something like this.

Code:
(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
Code:
`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
# 2  
Old 08-04-2009
try...

grep $(date '+ ( %m/%d/%Y %H') < file
# 3  
Old 08-04-2009
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
# 4  
Old 08-04-2009
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:
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:

Code:
> express=\$\\\(`date '+%m/%d/%Y'`\ "hour you want to filter"


Last edited by ilikecows; 08-04-2009 at 05:11 AM.. Reason: added comment
# 5  
Old 08-04-2009
i can't add that manually ..need to cron the script

And the $express from the above script seems to be returing null.
# 6  
Old 08-04-2009
in the last line try:

Code:
export express=\$\\\(`date '+%m/%d/%Y'`\ $stime

# 7  
Old 08-04-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Average of multiple time-stamped data every half hour

Hi All, Thank you for reading through my post and helping me figure out how I would be able to perform this task. For example: I have a list of continuous output collected into a file in the format as seen below: Date...........Time........C....A......... B ==========================... (5 Replies)
Discussion started by: terrychen
5 Replies

2. Shell Programming and Scripting

Grep in a log file within a time range (hour)

Hi, im trying to write a grep script that returns me the last inputs added in the last hour in the log file. Literally i have nothing yet but: grep 'Line im looking for' LOGFILE.log | tail -1 this only gives me the last input, but no necessarily from the last hour. Help Please. (4 Replies)
Discussion started by: blacksteel1988
4 Replies

3. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

4. UNIX for Advanced & Expert Users

Finding/Grep on files with date and hour in the file name

Hi, I have a folder structure as follows, DATA -> 2012-01-01 -> 00 -> ABC_2012-01-03_00.txt -> 01 -> ABC_2012-01-03_01.txt -> 02 -> ABC_2012-01-03_02.txt ... -> 23 -> ABC_2012-01-03_02.txt -> 2012-01-02 ... (1 Reply)
Discussion started by: mihirvora16
1 Replies

5. Shell Programming and Scripting

Finding/Grep on files with date and hour in the file name

Hi, I have a folder structure as follows, DATA -> 2012-01-01 -> 00 -> ABC_2012-01-03_00.txt -> 01 -> ABC_2012-01-03_01.txt -> 02 -> ABC_2012-01-03_02.txt ... -> 23 -> ABC_2012-01-03_02.txt -> 2012-01-02 -> 2012-01-03 So the dir DATA contains the above hierarchy, User input Start and... (6 Replies)
Discussion started by: mihirvora16
6 Replies

6. Shell Programming and Scripting

Grep string from logs of last 1 hour on files of 2 different servers and calculate count

Hi, I am trying to grep a particular string from the files of 2 different servers without copying and calculate the total count of its occurence on both files. File structure is same on both servers and for reference as follows: 27-Aug-2010... (4 Replies)
Discussion started by: poweroflinux
4 Replies

7. UNIX for Advanced & Expert Users

filter last 24 hour data and put in new file

i have file server 1 (filesvr01acess.log) and disc server 1 (discsvr01acess.log) in unix box(say ip adress of the box 10.39.66.81) Similiarly i have file server 2 (filesvr01acess.log) and disc server 2(discsvr01acess.log) in another unix box(say ip adress of the box 10.39.66.82). Now my... (1 Reply)
Discussion started by: nripa1
1 Replies

8. Shell Programming and Scripting

Counting average data per hour

Hi i have log like this : Actually i will process the data become Anybody can help me ? (6 Replies)
Discussion started by: justbow
6 Replies

9. Shell Programming and Scripting

generating data for 1 hour

Hi Folks, The reqirement is that i need to generate 1 hr file with a time interval of five minutes.. For ex: my i/p is 0000-0000 and desired o/p is 0000-0005 0005-0010 0010-0015 0015-0020 0020-0025 0025-0030 0030-0035 0040-0045 0050-0055 0055-0100 Script neede urgent ... (0 Replies)
Discussion started by: aajan
0 Replies

10. Shell Programming and Scripting

help in hour grep

i have this script that checks for yesterday date and also specific hour in that ----------------------------------------------------------------- TZ=`date +%Z`+24 ;a=`date +%Y-%m-%d %k` cd logs count=0 for i in DBMaint.log do cat $i | grep $a >> file12.txt done... (0 Replies)
Discussion started by: ali560045
0 Replies
Login or Register to Ask a Question