System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

script tp pull data from a log file ?

 
SOLVED
Go to solution
Jerry L. Sims
Frequent Advisor

script tp pull data from a log file ?

Hello All,

*****************************************
HP-UX B.11.11 9000/800/N4000-75
*****************************************
Does anyone know a way to get certain information from a log file, and place it into
another file ( maybe "sed" ).
example :

************************************
I have two log files I generate,

1) "memrpt.log" which simply is the output from "vmstat" command @ 10sec intervals( date & vmstat -n ), which looks like:

Thu Jul 1 16:42:31 PDT 2004 ,
CPU
us sy id
1 1 98
1 1 98
1 1 98
1 1 98
1 1 98
1 1 98

Thu Jul 1 16:42:41 PDT 2004 ,
CPU
us sy id
1 1 98
1 1 98
1 1 98
1 1 98
1 1 98
1 1 98

Thu Jul 1 16:42:51 PDT 2004 ,
CPU
us sy id
1 1 98
1 1 98
1 1 98
1 1 98
1 1 98
1 1 98

2) "cpurpt.log" which is output from
"vmstat" command @ 10 sec intervals ( date & vmstat ) which looks like :

Thu Jul 1 16:42:30 PDT 2004 , Free Memory=3579MB

Thu Jul 1 16:42:40 PDT 2004 , Free Memory=3579MB

Thu Jul 1 16:42:50 PDT 2004 , Free Memory=3579MB

Thu Jul 1 16:43:00 PDT 2004 , Free Memory=3579MB

Thu Jul 1 16:43:10 PDT 2004 , Free Memory=3579MB

Thu Jul 1 16:43:20 PDT 2004 , Free Memory=3580MB

Thu Jul 1 16:43:30 PDT 2004 , Free Memory=3580MB

Thu Jul 1 16:43:40 PDT 2004 , Free Memory=3581MB

Thu Jul 1 16:43:50 PDT 2004 , Free Memory=3579MB

Thu Jul 1 16:44:00 PDT 2004 , Free Memory=3579MB

*****************************************

These reports might run over 23 hours ( ex: 18:00 to 17:00 ), but I need to be able to pull certain time periods from these reports
(ex: 22:00 to 02:00 ). I have seen in "sar"
where it can have "start" & "end" time, and
deliver a report for just the requested time period. Right now I have to "vi" about 20 files
just deliver certain time periods. I would like to automate this process. If you know a way to do this, thanks. I'm reviewing some "sed" commands now.
5 REPLIES 5
RAC_1
Honored Contributor
Solution

Re: script tp pull data from a log file ?

sed -n '/22:/,/02:/p' file1
sed -n '/22:/,/02:/p' file2

Anil
There is no substitute to HARDWORK
Sundar_7
Honored Contributor

Re: script tp pull data from a log file ?

If sed with just /22:/ then it cannot differentiate between the hour or the minute field. So

How about this

START=$1
END=$2
LOG=/tmp/memrpt

sed -n "/ $START:/,/ $END:/p" $LOG

Learn What to do ,How to do and more importantly When to do ?
Mel Burslan
Honored Contributor

Re: script tp pull data from a log file ?

together with sed being the quickest way of accomplishing this task, it is not accurate as the hour string would not be the only string with the desired number, it may be the same as a cpu utilization percentage or a substring in free memory amount.

I am attaching a small script that I whipped up for the purpose. It is not bullet proof and not an absolute solution as well as not being tested due to the lack of data files. But the general idea is pretty simple and understandable.

Hope this helps.
________________________________
UNIX because I majored in cryptology...
Sundar_7
Honored Contributor

Re: script tp pull data from a log file ?

the colon (:) right after the search pattern in sed will ensure the pattern will not match any other data including memory or CPU usage.
Learn What to do ,How to do and more importantly When to do ?
Tim D Fulford
Honored Contributor

Re: script tp pull data from a log file ?

perl -ane 'if (m/21:00/ .. m/23:00/) { print "@F\n";} ' file

this will print ALL lines from the first instance of 21:00 until it reaches 23:00 so

20:00
21:00
22:00
23:00
24:00
00:00

so the above would retutn
21:00
22:00
23:00

HTH

Tim
-