Hi all,
I have been tasked with reading and parsing a large MIB file. I
eventually have to create the traps but that's beyond this post.
Currently I am looking for a certain line of text, and for the most part
what I have written works. Looking for lines similar to this:
dot3ChipSetAMD79C940 OBJECT IDENTIFIER ::= { dot3ChipSetAMD 3 }
dot3ChipSetIntel OBJECT IDENTIFIER ::= { dot3ChipSets 2 }
dot3ChipSetIntel82586 OBJECT IDENTIFIER ::= { dot3ChipSetIntel 1 22
4 5}
dot3ChipSetIntel82596 OBJECT IDENTIFIER ::= { dot3ChipSetIntel 2 }
But occasionally I get something like this:
dot3ChipSetIntel82596 OBJECT IDENTIFIER ::=
{ dot3ChipSetIntel 2 }
'or'
dot3ChipSetIntel82596
OBJECT IDENTIFIER ::=
{ dot3ChipSetIntel 2 }
So I need to search multiple lines for a string...but I cannot slurp the
whole file into memory ( Its currently over 12 megs), and I don't know
where the carriage return will be located.
I have several solutions in mind, one is using an queue (LIFO) and put new
lines read in so I would always have say the current line and the next line
in the list...then if I cant match I can concatenate the two lines together
and search that.
here is the test script I am currently using:
#!/usr/bin/perl -w
use strict;
select ( STDOUT );
$| = 1;
my $wRX = "\[\\w\\-\]";
my $commentRX = qr/^--/;
my $objectIdentifierRX = qr/^\s*($wRX+)\s+OBJECT\s+IDENTIFIER\s+::
=\s+{\s+($wRX+)\s+(\d+)\s*(\s+(\d+))+\s*}\s*$/;
open( MIB, "<master.mib") or die("Could not open master.mib\n");
print "- $objectIdentifierRX\n";
while( <MIB> )
{
my ($objectName, $objectParent, @objectIDs);
next if ( $_ =~ /$commentRX/ );
if ( $_ =~ m/$objectIdentifierRX/ )
{
print "$_";
}
elsif ( $_ =~ /OBJECT\s+IDENTIFIER/ )
{
print "**** $_";
sleep 1;
}
}
You can grab some sample mibs at:
ftp.cisco.com/pub/mibs/v1
Just cat them together to form a larger MIB.
Thanks.
-----------------------------------------
Craig Moynes
IBM Global Services, Canada
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]