[olug] script help

Obi-Wan obiwan at jedi.com
Wed Feb 20 04:37:32 UTC 2008


> If I can match anything between @d1 and @d2 that
> I am looking for then I want to print everything between the delimiters
> 
> @d1 ----------- linux host info ----------------------------
> 10:37pm  up 133 days,  4:16, 12 users,  load average: 0.09, 0.06, 0.00
> 250 processes: 248 sleeping, 1 running, 1 zombie, 0 stopped
> CPU0 states:  0.0% user,  0.0% system,  0.0% nice, 100.0% idle
> CPU1 states:  0.1% user,  4.0% system,  0.0% nice, 94.0% idle
> Mem:   513896K av,  495828K used,   18068K free,       0K shrd,  154432K buff
> Swap: 1056124K av,  222220K used,  833904K free                   92060K cached
> 
>   PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
> 20951 medelp    16   0  1228 1228   824 R     4.7  0.2   0:00 top
>     1 root      15   0   480  432   432 S     0.0  0.0   2:49 init
>     2 root      15   0     0    0     0 SW    0.0  0.0   0:00 keventd
>     3 root      34  19     0    0     0 SWN   0.0  0.0   0:01 ksoftirqd_CPU0
>     4 root      34  19     0    0     0 SWN   0.0  0.0   0:01 ksoftirqd_CPU1
>     5 root      15   0     0    0     0 SW    0.0  0.0   5:21 kswapd
>     6 root      15   0     0    0     0 SW    0.0  0.0   0:00 bdflush
>     7 root      15   0     0    0     0 SW    0.0  0.0  24:48 kupdated
>     8 root      25   0     0    0     0 SW    0.0  0.0   0:00 mdrecoveryd
>    14 root      25   0     0    0     0 SW    0.0  0.0   0:00 scsi_eh_0
>    18 root      15   0     0    0     0 SW    0.0  0.0   4:44 kjournald
>    84 root      17   0     0    0     0 SW    0.0  0.0   0:00 khubd
>   189 root      15   0     0    0     0 SW    0.0  0.0   0:09 kreiserfsd
> @d2

I haven't actually tested the following, but something like this seems
like it should probably do the trick.

#!/bin/perl
$hit=0;
while (<>) {
	$hit=1 if (/@d1/);
	next if ($hit == 0);
	$hit=0 if (/@d2/);
	s/^.*@d1//;
	s/@d2.*$//;
	print;
}


-- 
Ben "Obi-Wan" Hollingsworth                             obiwan at jedi.com
   The stuff of earth competes for the allegiance I owe only to the
     Giver of all good things, so if I stand, let me stand on the
       promise that You will pull me through.  -- Rich Mullins



More information about the OLUG mailing list