?
Solved

Script for File Formatting

Posted on 2006-04-19
4
Medium Priority
?
171 Views
Last Modified: 2010-03-05
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
     
0
Comment
Question by:dmshawkat
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
wlfs earned 160 total points
ID: 16494489
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
 
LVL 5

Expert Comment

by:wlfs
ID: 16494539
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question