Link to home
Start Free TrialLog in
Avatar of dmshawkat
dmshawkat

asked on

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
     
ASKER CERTIFIED SOLUTION
Avatar of wlfs
wlfs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wlfs
wlfs

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";
}