[HRPM] multiline match!!

Branson Matheson Branson.Matheson at FergInc.com
Tue Mar 13 14:13:17 CST 2001


On Tue, Mar 13, 2001 at 11:27:38AM -0800,Santiago Nieva did mutter:
> Hi everybody, 
> I failed this morning trying to filter a log that has
> "two line entries" like this:
> 
> 2001-03-07 msgID=4875876856     <--- line with date,
> hour
> User "nnnnnn" does not exists   <--- explanation text
> 2001-03-07 msg.....
> The applica....
> 
> What I wanna do is to get the "pair" filtered by date
> and explantion text. p.e collect all entries with date
> "xxxx" and text "not exists".

 Well.. there are a couple of ways to do this... if you have an entry 
 delimiter ... such as a blank line .. you can do something like:

 $/ = "/n/n";
 while ( $twolines = <IN> ) {
 	#-- do whatever
 }

 $/ is the input record seperator ( man perlvar ). It delimits lines
 that are returned using a filehandle.
 	
 If you don't .. you can do this if the lines are always exactly two
 lines .. ie .. you don't get a short entry that can be 1 or a long
 entry that can be 3

 while ( $twolines = <IN> ) {
 	# chomp; #-- if you don't want the \n in the middle.
	my $in = <IN>;
 	$twolines .= $in;

	#-- do whatever
 }

 Just make sure you start at the right place.

 If you need that nasty variable length one .. send me an example of
 your lines and I will reply with code.

  - branson

-------------------------------------------------------------------------------
Branson Matheson                       "If you are falling off of a mountain,
Manager, Risk and Information Security   You may as well try to fly." 
Ferguson Enterprises, Inc.               - Delenn, Minbari Ambassador 
           ( $statements = <BRANSON> ) !~ /Corporate Opinion/;



More information about the Norfolk-pm mailing list