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?
 
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";
}
0
 
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";
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.