Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If I've understood correctly, something along these lines might break your data into the records you need.

use strict; use warnings; my @records = (); my $inRecord = 0; my $rxRecStart = qr{^System:}; my $rxRecStop = qr{^CPU\sTTY}; my $recordStr = q{}; while( <DATA> ) { next if m{^\s*$}; if( m{$rxRecStart} ) { $inRecord = 1; push @records, $recordStr if $recordStr; $recordStr = $_; } elsif( m{$rxRecStop} ) { $inRecord = 0; push @records, $recordStr if $recordStr; $recordStr = q{}; } else { $recordStr .= $_ if $inRecord; } } foreach my $record ( @records ) { print $record, q{+} x 50, qq{\n}; } __END__ System: hpnclass Thu Feb 12 16:31:02 2009 Load averages: 0.51, 0.45, 0.49 541 processes: 483 sleeping, 58 running Cpu states: (avg) LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS 0.51 14.7% 3.0% 18.3% 63.9% 0.0% 0.0% 0.0% 0.0% Memory: 13706264K (11030248K) real, 18023572K (14848696K) virtual, 216 +916K free Page# 1/109 CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU C +OMMAND 1 ? 50 root 152 20 16032K 16032K run 17565:36 24.94 24.89 +vxfsd 2 ? 17979 ora102st 154 24 3989M 3588K sleep 384:22 4.65 4.65 o +ra_s002_pay9 0 ? 2553 ora102st 154 24 3991M 5520K sleep 3308:08 3.47 3.47 o +ra_s000_pay9 3 ? 6585 root 154 24 250M 63652K sleep 10144:59 3.27 3.27 +ucsrvwp 1 ? 17085 ora102st 154 24 3989M 5340K sleep 218:26 2.73 2.72 o +ra_s001_pay9 System: hpnclass Thu Feb 12 16:36:07 2009 Load averages: 0.52, 0.50, 0.50 520 processes: 461 sleeping, 59 running Cpu states: (avg) LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS 0.51 14.7% 3.0% 18.3% 63.9% 0.0% 0.0% 0.0% 0.0% Memory: 13706264K (11030248K) real, 18023572K (14848696K) virtual, 216 +916K free Page# 1/109 CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU C +OMMAND 1 ? 50 root 152 20 16032K 16032K run 17565:36 24.94 24.89 +vxfsd 2 ? 17979 ora102st 154 24 3989M 3588K sleep 384:22 4.65 4.65 o +ra_s002_pay9 0 ? 2553 ora102st 154 24 3991M 5520K sleep 3308:08 3.47 3.47 o +ra_s000_pay9 3 ? 6585 root 154 24 250M 63652K sleep 10144:59 3.27 3.27 +ucsrvwp 1 ? 17085 ora102st 154 24 3989M 5340K sleep 218:26 2.73 2.72 o +ra_s001_pay9

The output.

System: hpnclass Thu Feb 12 16:31:02 2009 Load averages: 0.51, 0.45, 0.49 541 processes: 483 sleeping, 58 running Cpu states: (avg) LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS 0.51 14.7% 3.0% 18.3% 63.9% 0.0% 0.0% 0.0% 0.0% Memory: 13706264K (11030248K) real, 18023572K (14848696K) virtual, 216 +916K free Page# 1/109 ++++++++++++++++++++++++++++++++++++++++++++++++++ System: hpnclass Thu Feb 12 16:36:07 2009 Load averages: 0.52, 0.50, 0.50 520 processes: 461 sleeping, 59 running Cpu states: (avg) LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS 0.51 14.7% 3.0% 18.3% 63.9% 0.0% 0.0% 0.0% 0.0% Memory: 13706264K (11030248K) real, 18023572K (14848696K) virtual, 216 +916K free Page# 1/109 ++++++++++++++++++++++++++++++++++++++++++++++++++

I hope this is of use.

Cheers,

JohnGG

Update: Corrected logic error in first if clause which was stripping the first line of the data wanted.


In reply to Re: Parsing a non-formatted record text file by johngg
in thread Parsing a non-formatted record text file by TStanley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-19 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found