Operating System - HP-UX
1753802 Members
8121 Online
108805 Solutions
New Discussion юеВ

Re: need script to add kr/s and kw/s columns for a specific time window

 
SOLVED
Go to solution
Mike_Ca Li
Regular Advisor

need script to add kr/s and kw/s columns for a specific time window

Wed Jul 9 00:29:55 2008
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
0.0 3.0 0.0 24.1 0.0 0.0 0.0 0.8 0 0 c6t0d51
0.0 1.0 0.0 8.0 0.0 0.0 0.0 0.5 0 0 c6t0d50
0.0 3.0 0.0 48.2 0.0 0.0 0.0 0.7 0 0 c6t0d40
0.0 1.0 0.0 8.0 0.0 0.0 0.0 0.4 0 0 c7t0d92
Wed Jul 9 00:29:56 2008
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
0.0 2.0 0.0 32.0 0.0 0.0 0.0 0.9 0 0 c6t0d50
0.0 1.0 0.0 8.0 0.0 0.0 0.0 2.6 0 0 c7t0d92
0.0 1.0 0.0 16.0 0.0 0.0 0.0 0.5 0 0 c7t0d50
Wed Jul 9 00:29:58 2008
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
Wed Jul 9 00:29:59 2008
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
0.0 3.0 0.0 24.1 0.0 0.0 0.0 1.0 0 0 c6t0d51
0.0 3.0 0.0 48.2 0.0 0.0 0.0 1.2 0 0 c6t0d40
Wed Jul 9 00:30:00 2008
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
0.0 1.0 0.0 8.0 0.0 0.0 0.0 0.4 0 0 c6t0d51
0.0 2.0 0.0 32.2 0.0 0.0 0.0 0.7 0 0 c6t0d50
0.0 1.0 0.0 16.1 0.0 0.0 0.0 0.5 0 0 c7t0d50
Wed Jul 9 00:30:01 2008
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
3.0 0.0 21.0 0.0 0.0 0.0 0.0 15.9 0 5 c6t0d92
22.0 145.1 176.1 1280.4 0.0 0.1 0.0 0.9 0 9 c6t0d89
0.0 3.0 0.0 24.0 0.0 0.0 0.0 0.7 0 0 c6t0d51
4.0 0.0 32.0 0.0 0.0 0.1 0.0 13.8 0 3 c7t0d92
2.0 14.0 16.0 128.0 0.0 0.0 0.0 0.6 0 1 c7t0d50
2.0 2.0 32.0 9.0 0.0 0.1 0.0 35.3 0 6 c3t0d0
Wed Jul 9 00:30:02 2008
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
0.0 2.0 0.0 32.2 0.0 0.0 0.0 0.6 0 0 c6t0d89
0.0 1.0 0.0 0.5 0.0 0.0 0.0 0.3 0 0 c6t0d52
0.0 7.0 0.0 112.7 0.0 0.0 0.0 1.2 0 0 c6t0d40
0.0 4.0 0.0 64.4 0.0 0.0 0.0 0.8 0 0 c7t0d89
0.0 2.0 0.0 32.2 0.0 0.0 0.0 0.9 0 0 c7t0d40

Eg for the first section:
Total Wed Jul 9 00:29:55 2008: kr/s 0.0 kw/s: 88.3

Anyone has attempted it?
Thank you.
14 REPLIES 14
James R. Ferguson
Acclaimed Contributor

Re: need script to add kr/s and kw/s columns for a specific time window

Hi :

# perl -nale 'if (/00:29:55/../00:29:56/) {$hdr||=$_;next unless /^\d/;$s2+=$F[2];$s3+=$F[3]};END{print "Total ",$hdr," kr/s ",$s2," kw/s ",$s3}'

...yields:

Total Wed Jul 9 00:29:55 2008 kr/s 0 kw/s 88.3

Regards!

...JRF...
Mike_Ca Li
Regular Advisor

Re: need script to add kr/s and kw/s columns for a specific time window

Thanks for reply.
Now, question is how to generate
perl -nale 'if (/00:29:56/../00:29:58/) {$hdr||=$_;next unless /^\d/;$s2+=$F[2];$s3+=$F[3]};END{print "Total ",$hdr," kr/s ",$s2," kw/s ",$s3}'
...

perl -nale 'if (/00:30:01/../00:30:02/) {$hdr||=$_;next unless /^\d/;$s2+=$F[2];$s3+=$F[3]};END{print "Total ",$hdr," kr/s ",$s2," kw/s ",$s3}'
James R. Ferguson
Acclaimed Contributor

Re: need script to add kr/s and kw/s columns for a specific time window

Hi:

With regard to your second question, specifying the range:

(/00:29:55/../00:30:02/)

...will correctly sum the appropriate columns although the description of the period will only represent the beginning argument.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: need script to add kr/s and kw/s columns for a specific time window

Hi (again):

OK, this is better. It will sum any range you specify and report the range used in the result:

# perl -nale 'if (/00:29:55/../00:30:02/) {$hdr||=$_;($trl=$_)=~m/(^\w{3}\s.+\d{4}$)/;next unless /^\d/;$s2+=$F[2];$s3+=$F[3]};END{print join " ","Total $hdr => $trl kr/s ",$s2,"kw/s",$s3}' file

Total Wed Jul 9 00:29:55 2008 => Wed Jul 9 00:30:02 2008 kr/s 277.1 kw/s 1714.3

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: need script to add kr/s and kw/s columns for a specific time window

Hi:

...and as a more general snippet (albeit without argument checking):

# perl -nale 'BEGIN{$beg=shift;$end=shift};if (/$beg/../$end/) {$hdr||=$_;($trl=$_)=~m/(^\w{3}\s.+\d{4}$)/;next unless /^\d/;$s2+=$F[2];$s3+=$F[3]};END{print join " ","Total $hdr => $trl kr/s ",$s2,"kw/s",$s3}' 30:00 30:02 file

Total Wed Jul 9 00:30:00 2008 => Wed Jul 9 00:30:02 2008 kr/s 277.1 kw/s 1497.7

...That is, pass three arguments, the beginning range, the ending range, and the name of the file containing the data.

Regards!

...JRF...
Mike_Ca Li
Regular Advisor

Re: need script to add kr/s and kw/s columns for a specific time window

Looks good. Last question:
Having following:
0:29:20
0:29:21
0:29:22
0:29:23
0:29:25
0:29:26
0:29:27
0:29:28
0:29:29
0:29:30
0:29:31
0:29:32
0:29:33
0:29:34
0:29:36
0:29:37
0:29:38
0:29:39
0:29:40
0:29:41
0:29:42
0:29:43

How to get:
0:29:20 0:29:21
0:29:21 0:29:22
0:29:22 0:29:23
0:29:23 0:29:25
0:29:25 0:29:26
0:29:26 0:29:27
0:29:27 0:29:28
0:29:28 0:29:29
0:29:29 0:29:30
0:29:30 0:29:31
0:29:31 0:29:32
0:29:32 0:29:33
0:29:33 0:29:34
0:29:34 0:29:36
0:29:36 0:29:37
0:29:37 0:29:38
0:29:38 0:29:39
0:29:39 0:29:40
0:29:40 0:29:41
0:29:41 0:29:42
0:29:42 0:29:43
Arturo Galbiati
Esteemed Contributor
Solution

Re: need script to add kr/s and kw/s columns for a specific time window

HI,
you can use the Unix command paste.
See man for more info.
HTH,
Art
Dennis Handly
Acclaimed Contributor

Re: need script to add kr/s and kw/s columns for a specific time window

>Last question: Having following:
0:29:20

And you can also use awk to read two at a time:
awk '
{
getline second
print $0, second
}' file

>Arturo: you can use the Unix command paste.

paste(1) seems to want to put them all on one line.
Mike_Ca Li
Regular Advisor

Re: need script to add kr/s and kw/s columns for a specific time window

The awk command created:
00:29:19 00:29:20
00:29:21 00:29:22
00:29:23 00:29:25
00:29:26 00:29:27
00:29:28 00:29:29
00:29:30 00:29:31
00:29:32 00:29:33
00:29:34 00:29:36
00:29:37 00:29:38
00:29:39 00:29:40
00:29:41 00:29:42
00:29:43 00:29:44
...

Instead of:
0:29:20 0:29:21
0:29:21 0:29:22
0:29:22 0:29:23
0:29:23 0:29:25
0:29:25 0:29:26
0:29:26 0:29:27
0:29:27 0:29:28
0:29:28 0:29:29
0:29:29 0:29:30
0:29:30 0:29:31
0:29:31 0:29:32
0:29:32 0:29:33
0:29:33 0:29:34
0:29:34 0:29:36
0:29:36 0:29:37
0:29:37 0:29:38
0:29:38 0:29:39
0:29:39 0:29:40
0:29:40 0:29:41
0:29:41 0:29:42
0:29:42 0:29:43