Command to grep the service with in a timeframe


 
Thread Tools Search this Thread
Operating Systems Solaris Command to grep the service with in a timeframe
# 1  
Old 10-27-2015
Display Command to grep the service with in a timeframe

Guys,

I am trying to use this command to find out the occurrence of the service "Loadservice" from the log file "log.06102010.svr1" in between the time frame 02:00:00 to 03:00:00 on the day 06-10-2010.

Code:
sed -n '/2010-06-10 02:00:00/,/2010-06-10 03:00:00/p' | fgrep "Loadservice" log.06102013.svr1 | wc -w

I just need to find the wordcount of Loadservice and I am getting incorrect outcome from the above command. Any help will be really appreciated.

Regards,
Kris

Last edited by Don Cragun; 10-27-2015 at 05:38 PM.. Reason: Add CODE tags.
# 2  
Old 10-27-2015
sed doesn't work that way. If you don't have a line EXACTLY matching 2010-06-10 02:00:00, it will never begin, and if you don't have a line EXACTLY matching 2010-06-10 03:00:00 it will never end.

Also, word count probably isn't what you're looking for, but the number of lines containing that word.

You can probably do it with awk, but we will need to see what your logfile looks like.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 10-27-2015
I need the number of words of 'Loadservice' between 2-3 AM
# 4  
Old 10-27-2015
Show a line with 'loadservice' in it and how you expect it to be counted.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 10-27-2015
The first command in your pipe should open the file; the second command should default to its stdin (that reads from the pipe).
But perhaps can be boiled down to one sed command
Code:
sed -n '/2010-06-10 02:/,/2010-06-10 03:/{/Loadservice/p;}' log.06102013.svr1

Still it needs to find at least one 02: and one 03: entry in the file.
It is identical with
Code:
sed '/2010-06-10 02:/,/2010-06-10 03:/!d;/Loadservice/!d' log.06102013.svr1

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 10-28-2015
Thanks MadeinGermany.

Tats works perfectly fine and if you add grep Loadservice | wc -l at the end it gives me the perfect count.

sed '/2010-06-10 02:/,/2010-06-10 03:/!d;/Loadservice/!d' log.06102013.svr1 |grep Loadservice | wc -l

---------- Post updated at 09:28 AM ---------- Previous update was at 09:26 AM ----------

I need the count for every hour, so I am trying to put this in a script which gives me the output for every single hour from 00:00 to 23:00
# 7  
Old 10-28-2015
Quote:
Originally Posted by Corona688
Show a line with 'loadservice' in it and how you expect it to be counted.
Please show a line with 'loadservice' in it and how you expect it to be counted.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Viewing a specific timeframe of a log file

Hi guys Done a bit of research online but can't seem to figure it out, is there anyway of grepping or using sed to view a specific time period of a log file. I am trying to view a log file for Saturday 22nd April between 08:00 - 12:00 I saw this command online and tried but doesn't seem to... (10 Replies)
Discussion started by: simpsa27
10 Replies

2. SuSE

Is this iostat pipe to sort service request command correct?

Hi, my os is SLES 10 from sort iostat as my output does not include rkB/s and wkB/s I probably have to adjust the key position, so is the following iostat pipe to sort service request command correct? oracle@vmc_stallite:~> iostat -x | sort -nrk11 sda 0.96 ... (4 Replies)
Discussion started by: jediwannabe
4 Replies

3. Red Hat

No reponse to 'service NFS start' command

Hello, I have a newly kickstarted RHEL 6.4 server that I'm trying to set-up as a kickstart server. I have done this before on other machines, but I am encountering some strange behaviour in this one. # service nfs status rpc.svcgssd is stopped rpc.mountd is stopped nfsd is stopped... (0 Replies)
Discussion started by: Chopstyx
0 Replies

4. Solaris

Logging out idle users after a certain timeframe

We recently underwent a security audit and have a new requirement to not allow users to stay logged on overnight. In order to place this policy into effect i need a way to check for idle users and log them off. Is there any good way to enforce this policy in Solaris 10 and make it work in such a... (11 Replies)
Discussion started by: goose25
11 Replies

5. Shell Programming and Scripting

Date within a timeframe 2 days ago

How could I using the following example, change it to show 2 days ago within the same time frame 0600 AM to 0600 AM let foo=`date "+(1%H-106)*60+1%M-100"` bar=foo+1440 find . -mmin +$foo -mmin -$bar | tr -s '/','-' '^' | cut -f2,3 -d"^" | tr -s '^' ' ' | Please use code tags (7 Replies)
Discussion started by: freddie999
7 Replies

6. Shell Programming and Scripting

print contents of any file within some timeframe

Hi, Is there anyway to print contents of any file ( say log files that grow automatically) within some timeframe ( comparing with current time), say print contents of the added in: 1) last 2 hr 2) last 45 min 3) last 3 hrs 47 min (3 Replies)
Discussion started by: fed.linuxgossip
3 Replies
Login or Register to Ask a Question