[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] script advice



According to Jordan S Dill:
> 
> 	Good day all...
Howdy! :-)

> grep "Dec  6" /var/log/termlog | egrep
> "pm0a22.sta|206.25.68.122"...really, a very simple process

This should be fairly simple and straight forwards.  :-)  Try this:

#!perl
#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#
	open(THEFILE, "/var/log/termlog") || die $!;
#
#	Since I'm assuming that termlog is quite large - we really
#	do not wish to bring down the system by trying to read it
#	all in at once.
#
	while( <THEFILE> ){
		if( /Dec  6/i ){
#
#	Do your thing here and extract the information you want.
#
#	For example:  Let's say you want to break everything up
#	by white space.  This would leave you with something like
#	this:
#
#		myVar[0] = "Dec";
#		myVar[1] = "6";
#		myVar[2] = "pm0a22.sta";
#		myVar[3] = "206.25.68.122";
#
#		and so on....
#
#	Here's how you do it:
#
			@myVar = split( /\s/ );
#
#	myVar now contains the entire record split up.  The next
#	thing to think about is: What about commas, semicolons,
#	and the like.  Well, you can just split things up
#	by the various items on an as needed basis.  What I'm
#	trying to do is simply give you an idea about how to
#	go about doing this.  :-)
#
#	I would suggest writing about ten of these lines out
#	to a file and then stopping the program and looking at
#	the "myVar" information.  Like so:
#
			for( $i=0; $i<=$#myVar; $i++ ){
				print "$i. $myVar[$i]\n";
				}

			print "\n\n";
#
#	This will give you a good idea where all of the information
#	will fall when it is split up.
#
			}
		}

	close( THEFILE );
	exit( 0 );
#
#	Have fun!  :-)
#
#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch