thebarn...@gmail.com wrote:
Hi

Hello,

I run this command and pipe the output to a perl one liner.  not quite
sure how it parses the data:
svmon -Pt3 | perl -e 'while(<>){print if($.==2 || $& && !$x++); $.=0 if
(/^--+$/)}'

That can be shortened to:

svmon -Pt3 | perl -ne'print if $.==2 || $& && !$x++; $.=0 if /^--+$/'

The -n switch provides the while loop for you.


which outputs:
-------------------------------------------------------------------------------
     Pid Command          Inuse      Pin     Pgsp  Virtual 64-bit
Mthrd  16MB
 1450182 oracle         2567301    65584  1345587  3132033      Y
N     N
 1179888 oracle         2117480    65584  1343450  2680222      Y
N     N
 1446084 oracle         2115481    65840  1346761  2681480      Y
N     N
--
The ouput it is parsing looks like this:

-------------------------------------------------------------------------------
     Pid Command          Inuse      Pin     Pgsp  Virtual 64-bit
Mthrd  16MB
 1450182 oracle         2501222    65586  1345953  3066501      Y
N     N

     PageSize      Inuse        Pin       Pgsp    Virtual
       238845         - clnt /dev/fslv00:41875            s      0
0    -     -
...
-------------------------------------------------------------------------------
     Pid Command          Inuse      Pin     Pgsp  Virtual 64-bit
Mthrd  16MB
 1794286 oracle         2131397    65604  1343816  2695867      Y
N     N

     PageSize      Inuse        Pin       Pgsp    Virtual
     s   4 KB    2063541         20    1343816    2628011
 .....

and so on
--
i understand that it resets the line count  every time it sees  a line
of "----" and it then will print line 2  which is the summary line we
are looking for.   not sure what this part does "($.==2 || $& && !$x+
+)"

perl -ne'print if $.==2 || $& && !$x++; $.=0 if /^--+$/'

The $.==2 tests if the current line number is 2. If $. is 2 then the current line is printed and the program goes on to the next statement. If $. is not 2 then $& is tested and if $& is false then the current line is printed and the program goes on to the next statement. If $& is true then $x is negated and tested and incremented (in that order) and if $x is true then the program goes on to the next statement else if $x is false then the current line is printed.



John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to