Script for File Formatting

I need a script( SUN Solaris OS)  that would
 read certain lines (lines that match with given string)  in a text  file  then , the script would generate a formatted output file (or statistics)



input read file is below.

#BEGIN LOGRECORD number = 133
TYPE = OPERATIONAL
FDN=O%:CCLN-1-CBS1:SBSS-1-SBSS1:SBSCSUBSYSTEM-1-SBSCSUBSYSTEM11:ROOT-1-ROOT1:SBS-1-SBS1:ESBSSHELF-1-ESBSSHELF1:ESELECTORCARD-1-ESELECTORCARD5

Event Name: ConsolidatedOMs
Originator OID: 69.2.0.175.1.5
Manager OID: 69.2.0.175.1.5
Event ID: (Type=0xB6, Seq=0x03)

OM Group: SCH Burst Setup
Pegging Type: Node

 Application ID: 0

           Performance Data Value: 0
        Performance Attribute Name: FwdBurstSetupFailures_2X
        Performance Data Value: 0
        Performance Attribute Name: FwdBurstSetupFailures_4X
        Performance Data Value: 0
        Performance Attribute Name: FwdBurstSetupFailures_8X
        Performance Data Value: 0
        Performance Attribute Name: FwdBurstSetupFailures_16X

The script would read lines that match all three string SBSCSUBSYSTEM24 , ESELECTORCARD1 and OM Group: SCH Burst Setup

then the script would output a formatted file that contain

 FwdBurstSetupFailures_8X = 0 ( here it could be zero or any other number)
 
 FwdBurstSetupFailures_16X =0
       


Thanks
     
dmshawkatAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wlfsCommented:
open my $fh, "<", "infile.txt";
$/ = "#BEGIN LOGRECORD ";
while (<$fh>) {
  index($_, "SBSCSUBSYSTEM24") < 0 ||
  index($_, "ESELECTORCARD1") < 0 ||
  index($_, "OM Group: SCH Burst Setup") < 0  and next;
  print "#BEGIN LOGRECORD ", m/^(number = \d+)/, "\n";
  my @failure = m/Performance Data Value: (\d+)\s+Performance Attribute Name: (FwdBurstSetupFailures_\d+X)/g;
  while (@failure) {
    my $value = shift @failure;
    print shift(@failure) . " = $value\n";
  }
  print "\n";
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wlfsCommented:
Or did you mean to sum the number of failures over all log records?
This would be:

open my $fh, "<", "ee_12.txt";
$/ = "#BEGIN LOGRECORD ";
my %stats;
while (<$fh>) {
  index($_, "SBSCSUBSYSTEM24") < 0 ||
  index($_, "ESELECTORCARD1") < 0 ||
  index($_, "OM Group: SCH Burst Setup") < 0  and next;
  my %failures = reverse m/Performance Data Value: (\d+)\s+Performance Attribute Name: FwdBurstSetupFailures_(\d+)X/g;
  $stats{$_} += $failures{$_} foreach keys %failures;
}
foreach (sort {$a <=> $b} keys %stats) {
    print "FwdBurstSetupFailures_${_}X = $stats{$_}\n";
}
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.