Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Parsing a non-formatted record text file

by johngg (Abbot)
on Feb 16, 2009 at 16:44 UTC ( #744128=note: print w/ replies, xml ) Need Help??


in reply to Parsing a non-formatted record text file

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.


Comment on Re: Parsing a non-formatted record text file
Select or Download Code
Re^2: Parsing a non-formatted record text file
by TStanley (Canon) on Feb 16, 2009 at 19:27 UTC
    Thank you. This helped me immensely, by getting rid of the data that I didn't need, and by putting in a record separator, it makes it easier for me to work with.

    TStanley
    --------
    People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://744128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2014-10-22 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (119 votes), past polls