Pandey Rajeev-A19514 wrote:
>
> Rob ANderson wrote:
> >
> > Pandey Rajeev-A19514 wrote:
> > >
> > > In short, I have a defined set of pattern that can occur across any number of 
> > > lines(scalars) in a buffer (array of scalars)
and I need to print only those lines(Scalars) that contain the full or partial 
pattern. For eg. For the buffer @buff (as shown
below), I have to find out the occurance of "FastEthernet" and "down".
> > >
> > > I have pasted a code below :
> > > I join the buffer to make a Scalar and then search for the pattern.
> > >
> > > ********************************************************************************************
> > > my @buff;
> > > $buff[0] = "Jul  5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping 
> > > packet
> > > $buff[1] = " ifEntry.1.13 = 13
> > > $buff[2] = " ifEntry.2.13 = FastEthernet3/9
> > > $buff[3] = " ifEntry.3.13 = 6
> > > $buff[4] = " lifEntry.20.13 = administratively down
> > > $buff[5] = " ifEntry.2.13 = FastEthernet3/9
> > > $buff[6] = " ifEntry.3.13 = 6
> > > $buff[7] = " lifEntry.20.13 = administratively down
> > >
> > > $temp = join($",@buff);
> > > if($temp =~ /FastEthernet(\n|\d|\w|\.|\/|\s|=)*down/i) {
> > >     print "MATCH found
> > > }
> > > ***********************************************************************************************
> > >
> > > Now, that the match has been found, I just want to print only those scalars in 
> > > @buff which contains the specified pattern.
> > >
> > > The print should be
> > > ifEntry.2.13 = FastEthernet3/9
> > > lifEntry.20.13 = administratively down
> >
> > I'm not sure why you feel the need to join your buffer into a big string.
> > From what you describe couldn't you just process each buffer element one by
> > one?
> >
> > foreach my $buffer_entry (@buff) {
> >     if($buffer_entry =~ /(FastEthernet|down)/i) {
> >         print $buffer_entry;
> >     }
> > }
> >
> > Let us know if your trying to do something more complicated that I've not
> > understood.
>
> Yes, I need a tight pattern representation because the buffer I need to parse is 
> slightly complicated than what I had pasted in
the mail.
>
> /(FastEthernet|down)/i) gives me an option of "FastEthernet" OR "down".
>
> I want something like "FastEthernet" AND "down". How do we give AND operation ?
>
> I want my match to be successful only if all the patterns matches. I thought that 
> there might be an easy way to represent them
thru Regex and would not have to do any if-else ckecking.
>
> Please tell me if you understood my needs or else I will send a bigger mail.

Hi Rajeev.

It sounds like you have a log file (?) which looks something like

 Jul  5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping packet
 ifEntry.1.13 = 13
 ifEntry.2.13 = FastEthernet3/9
 ifEntry.3.13 = 6
 lifEntry.20.13 = administratively down
 ifEntry.2.13 = FastEthernet3/9
 ifEntry.3.13 = 6
 lifEntry.20.13 = administratively down

and you need to find sets of lines which contain both 'FastEthernet'
and administratively down. If I'm right, can you explain better how the
lines in these sets are related so that we know they belong together,
and how we tell where the sets start and end?

Just to give us something to talk about, is this any help?

Rob



  use strict;
  use warnings;

  while (<DATA>) {
    print if /FastEthernet/ .. /administratively down/;
    print "\n" if /administratively down/;
  }

  __DATA__
   Jul  5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping packet
   ifEntry.1.13 = 13
   ifEntry.2.13 = FastEthernet3/9
   ifEntry.3.13 = 6
   lifEntry.20.13 = administratively down
   ifEntry.2.13 = FastEthernet3/9
   ifEntry.3.13 = 6
   lifEntry.20.13 = administratively down

OUTPUT

 ifEntry.2.13 = FastEthernet3/9
 ifEntry.3.13 = 6
 lifEntry.20.13 = administratively down

 ifEntry.2.13 = FastEthernet3/9
 ifEntry.3.13 = 6
 lifEntry.20.13 = administratively down




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to