In article <[EMAIL PROTECTED]>, Rob Dixon wrote: > 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. >> > > [...] >> > > 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
[...] Or if you don't need the lines in between the first and second match (as in Rob's example), then maybe a "state-machine"-like marker (I saw an article recently about state machines) will help. John W. Krahn justed posted something similar I think... my $match = ''; while (<DATA>) { if (/.*FastEthernet.*/) { $match = 1; print $_; } if (/.*administratively down.*/ and $match) { print; $match = ''; } } __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 This produces: ifEntry.2.13 = FastEthernet3/9 lifEntry.20.13 = administratively down ifEntry.2.13 = FastEthernet3/9 lifEntry.20.13 = administratively down But your example only printed one of these, so I'm not sure if that is what you wanted. -K -- Kevin Pfeiffer International University Bremen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]