grep time and date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep time and date
# 1  
Old 12-18-2007
grep time and date

Hi,

I have a file which is a result of a script running every two minutes. What I wanted to do is to grep a specific date and time (hour and minute) from the file and then count the occurance of 201. I need to get the result of occurance of 201 every 5 minutes. What should I include in my command below to do that? I know I need to create variables for the date, just don't know how to do it. Thanks in advance! I hope someone can help me.

cat result.txt | nawk '{print $9}' | grep "201" | wc -l


Code:
Via NODE 4 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60232010 bbbbbbbb0232010 0.0 -1 0.0 0 0 
Via NODE 0 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa99461665 bbbbbbbb65      0.0 -1 0.0 0 0 
Via NODE 7 CP2 20071217 17:59:54 20071217 17:59:59 201 103 644 aaaaaaaa62179668 bbbbbbbb2179668 0.0 -1 0.0 0 0 
Via NODE 7 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60239184 bbbbbbbb0239184 0.0 -1 0.0 0 0 
Via NODE 0 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60230772 bbbbbbbb0230772 0.0 -1 0.0 0 0 
Via NODE 2 CP2 20071217 17:59:54 20071217 17:59:59 201 103 630 aaaaaaaa60252750 bbbbbbbb0252750 0.0 -1 0.0 0 0

# 2  
Old 12-18-2007
try this:
Code:
cat result.txt | grep " 17:59:" | grep -c " 201 "

# 3  
Old 12-18-2007
You don't need so many different 'piped' tools (let alone UUoC)
Not sure I fully understand the requirement......
What's your input? Date? Or data AND time (hour/minute)?
Why do you need 'hour/minute' if you if want to stat count for every FIVE minutes worth of data?
If would help if you could provide
  1. a better/respresentative data sample
  2. what the expected input parameter(s) supposed to be
  3. what the desired output supposed to be
# 4  
Old 12-18-2007
Quote:
Originally Posted by Yogesh Sawant
try this:
Code:
cat result.txt | grep " 17:59:" | grep -c " 201 "

or better yet:
Code:
cat result.txt | egrep " 17:(55|56|57|58|59):" | grep -c " 201 "

# 5  
Old 12-18-2007
grep time and date

Hi,

Thanks for the response. What I need to do is to get the number of occurance of "201" every 5 minutes based on the time from the result.txt file. For example:



Output:

2007-12-18_17:59: to 18:04 201Count=301
2007-12-18_18:05: to 18:09 201Count=100
2007-12-18_18:10: to 18:14 201Count=798

and so on...
# 6  
Old 12-18-2007
Quote:
Originally Posted by Yogesh Sawant
or better yet:
Code:
cat result.txt | egrep " 17:(55|56|57|58|59):" | grep -c " 201 "

vgersh99 was saying about the UUOC

you don't need a cat there.
# 7  
Old 12-18-2007
grep time and date

Hi Matrixmadhan,

It's you again and it's me again! Smilie I don't need a specific date and time. What I need to do is to count the number of occurance of 201 every interval of 5 minutes continously. The result.txt file is continously being appended by data like the sample below. I hope you can help me.


contents of result.txt:
Via NODE 4 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60232010 bbbbbbbb0232010 0.0 -1 0.0 0 0
Via NODE 0 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa99461665 bbbbbbbb65 0.0 -1 0.0 0 0
Via NODE 7 CP2 20071217 17:59:54 20071217 17:59:59 201 103 644 aaaaaaaa62179668 bbbbbbbb2179668 0.0 -1 0.0 0 0
Via NODE 7 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60239184 bbbbbbbb0239184 0.0 -1 0.0 0 0
Via NODE 0 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60230772 bbbbbbbb0230772 0.0 -1 0.0 0 0
Via NODE 2 CP2 20071217 18:01:54 20071217 17:59:59 201 103 630 aaaaaaaa60252750 bbbbbbbb0252750 0.0 -1 0.0 0 0
Via NODE 4 CP2 20071217 18:01:53 20071217 17:59:59 201 103 630 aaaaaaaa60232010 bbbbbbbb0232010 0.0 -1 0.0 0 0
Via NODE 0 CP2 20071217 18:02:53 20071217 17:59:59 201 103 630 aaaaaaaa99461665 bbbbbbbb65 0.0 -1 0.0 0 0
Via NODE 7 CP2 20071217 18:04 20071217 17:59:59 201 103 644 aaaaaaaa62179668 bbbbbbbb2179668 0.0 -1 0.0 0 0
Via NODE 7 CP2 20071217 18:05:53 20071217 17:59:59 201 103 630 aaaaaaaa60239184 bbbbbbbb0239184 0.0 -1 0.0 0 0
Via NODE 0 CP2 20071217 18:08:53 20071217 17:59:59 201 103 630 aaaaaaaa60230772 bbbbbbbb0230772 0.0 -1 0.0 0 0
Via NODE 2 CP2 20071217 18:09:54 20071217 17:59:59 201 103 630 aaaaaaaa60252750 bbbbbbbb0252750 0.0 -1 0.0 0 0



Hi Matrixmadhan,

It's you again and it's me again! Smilie I don't need a specific date and time. What I need to do is to count the number of occurance of 201 every interval of 5 minutes continously. The result.txt file is continously being appended by data like the sample below. I hope you can help me.


Code:
Via NODE 4 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60232010 bbbbbbbb0232010 0.0 -1 0.0 0 0 
Via NODE 0 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa99461665 bbbbbbbb65      0.0 -1 0.0 0 0 
Via NODE 7 CP2 20071217 17:59:54 20071217 17:59:59 201 103 644 aaaaaaaa62179668 bbbbbbbb2179668 0.0 -1 0.0 0 0 
Via NODE 7 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60239184 bbbbbbbb0239184 0.0 -1 0.0 0 0 
Via NODE 0 CP2 20071217 17:59:53 20071217 17:59:59 201 103 630 aaaaaaaa60230772 bbbbbbbb0230772 0.0 -1 0.0 0 0 
Via NODE 2 CP2 20071217 18:01:54 20071217 17:59:59 201 103 630 aaaaaaaa60252750 bbbbbbbb0252750 0.0 -1 0.0 0 0 
Via NODE 4 CP2 20071217 18:01:53 20071217 17:59:59 201 103 630 aaaaaaaa60232010 bbbbbbbb0232010 0.0 -1 0.0 0 0 
Via NODE 0 CP2 20071217 18:02:53 20071217 17:59:59 201 103 630 aaaaaaaa99461665 bbbbbbbb65      0.0 -1 0.0 0 0 
Via NODE 7 CP2 20071217 18:04 20071217 17:59:59 201 103 644 aaaaaaaa62179668 bbbbbbbb2179668 0.0 -1 0.0 0 0 
Via NODE 7 CP2 20071217 18:05:53 20071217 17:59:59 201 103 630 aaaaaaaa60239184 bbbbbbbb0239184 0.0 -1 0.0 0 0 
Via NODE 0 CP2 20071217 18:08:53 20071217 17:59:59 201 103 630 aaaaaaaa60230772 bbbbbbbb0230772 0.0 -1 0.0 0 0 
Via NODE 2 CP2 20071217 18:09:54 20071217 17:59:59 201 103 630 aaaaaaaa60252750 bbbbbbbb0252750 0.0 -1 0.0 0 0

Expected Output:

2007-12-18_17:59: to 18:04 201Count=301
2007-12-18_18:05: to 18:09 201Count=100
2007-12-18_18:10: to 18:14 201Count=798
and so on...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Does 'grep' update a file's access date/time?

I've got a job that finds and removes trace files based upon an access time of more than seven days (I've also tried a modify date). find TABC* -atime +7 -exec rm + find TABC* -mtime +7 -exec rm + Whether I use -atime or -mtime, the process seems to work sporadically. Sometimes it removes... (6 Replies)
Discussion started by: Scottie1954
6 Replies

2. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

3. Shell Programming and Scripting

Adding time to date time in UNIX shell scipting

I needed some help in adding a duration (in seconds) to a start time (in hhmmss format) and a start date (in mmddyy format) in order to get an end date and end time. The concept of a leap year is also to be considered while incrementing the day. The code/ function that I have formed so far is as... (3 Replies)
Discussion started by: codehelp04
3 Replies

4. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

5. UNIX Desktop Questions & Answers

grep a range of time & date

how can i grep a range? i have a text file with the following text: result.log.00:2012/01/02 12:00:07.422 LOG STARTED HERE N6Kashya29MemoryShieldScheduler_AO_IMPLE, pid=8662/8658, config=(alertThreshold=10,alertLevel=0,killThreshold=7200,coreThreshold=0,full=1), deltaTime=0,... (1 Reply)
Discussion started by: boaz733
1 Replies

6. Shell Programming and Scripting

Grep the Content of a LOG File which has latest Date and Time

Hi All, Need a small help. I have a log file which keeps updating for every Minute with multiple number of lines. I just want to grep few properties which has latest Date and Time to it. How do i do it? I wanted to grep a property by name "Reloading cache with a maximum of" from the... (4 Replies)
Discussion started by: nvindraneel
4 Replies

7. Shell Programming and Scripting

grep - date & time range

Hi, I need to search email files by date & time range in email files. The timezone is not important. Can someone plz advise how i can do this ? For e.g A user can specify only A single date A date range date & time range Below is part of the email file. (4 Replies)
Discussion started by: coolatt
4 Replies

8. Shell Programming and Scripting

Show date/time with tail|grep command

Hi, I have a log file without date/time, and I want that everytime tail|grep find something it displays the date/time and the line. I have tried something like this command but without any luck to display the date/time: tail -F catalina.out | sed "s/^/`date `/" | egrep ... (6 Replies)
Discussion started by: julugu
6 Replies

9. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

10. Shell Programming and Scripting

grep to show date/time of file the string was found in.

I've seen several examples of grep showing the filename the string was found in, but what I really need is grep to show the file details in long format (like ls -l would). scenario is: grep mobile_number todays_files This will show me the string I'm after & which files they turn up in, but... (2 Replies)
Discussion started by: woodstock
2 Replies
Login or Register to Ask a Question