Operating System - HP-UX
1752797 Members
5873 Online
108789 Solutions
New Discussion юеВ

sar -d output reformatting

 
SOLVED
Go to solution
Rex Pommier
Frequent Advisor

sar -d output reformatting

Hi.

Is there some way (script or otherwise)to reformat the output of the sar -d output to put the time stamp on every line? For example I have the following output (truncated):
13:02:00 c0t1d0 3.23 0.50 3
c0t0d0 0.13 0.50 0
c2t0d0 0.08 0.50 0
I would like to be able to get the "13:02:00" on all three lines and haven't come up with a way to do it.

TIA. Rex
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: sar -d output reformatting

Hi Rex:

A quick-and-dirty reformat could be:

# sar -d 10 10|awk '{if (NF==1) {next};if (NF==8) {DEV=$1} else {$0=DEV$0};print}'

Regards!

...JRF...

Hein van den Heuvel
Honored Contributor

Re: sar -d output reformatting

Similar using Perl...

sar -d 3 3 | perl -pe 'if (/^([0-9:]+)/){$t=$1} else {s/^( ){8}/$t/}'


-p --> makes perl loop
^([0-9:]+) --> matches and remember a timestamp at start of line

s/^( ){8}/$t/ --> replaces 8 spaces, and only 8 spaces, at begin of line with last time seen


Hein.
Rex Pommier
Frequent Advisor

Re: sar -d output reformatting

AWESOME!!!!! They both work like champs. Someday when/if I ever get my head above water I will hopefully get to take the time to learn awk and perl.

Rex
Rex Pommier
Frequent Advisor

Re: sar -d output reformatting

Just wish I could give more points!! Both responses dis just what I wanted.
James R. Ferguson
Acclaimed Contributor

Re: sar -d output reformatting

Hi Rex:

Learn enough 'awk' to be able to read, understand and modify existing scripts.

http://www.gnu.org/software/gawk/manual/

Then, use Perl! Perl has an extremely robust, feature-extensive regular expression engine built into it. With Perl you can parse anything. Many things that would otherwise require you to write in C can be done with ease and speed of development in Perl.

http://learn.perl.org/

Regards!

...JRF...