Looking for a regular expression

Jeffrey Wong jmwong at hoku.net
Tue Jul 24 01:45:17 PDT 2001


What you have is pretty close to one way of doing it.  This would be a
little better:

egrep -e "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" /var/log/messages

This should look for a sequence of 4 numbers consisting of between 1 and 3
digits each, separated by dots.  It won't filter out numbers larger than
255 but that shouldn't be a problem.  If you really want something that
will do bounds checking I could probably whip up a little script, but that
seems like alot of work for a minor thing and I'm feeling lazy right now
;)


Jeff W.

On Tue, 24 Jul 2001 beesond001 at hawaii.rr.com wrote:

> To all,
> 	I'm looking for a regular expression that will fetch IP addresses from a 
> file such as /var/log/messages etc.  So far, I have a start, it looks 
> like this:
> 	$ grep "[0-9]\{2\}.[0-9]\{3\}.[0-9]\{2\}.[0-9]\{2\}" /var/log/messages  
> Unfortunately, it only works for certain types of IP addresses, those 
> with a form of  AA.BBB.CC.DD.  Is there a more general approach to 
> grabbing IP addresses, or will I have to write several forms of the above 
> regex and apply them all?  
> Thanks in advance,
> Ben 
> 
>  
> 
> 
> 
> ---
> You are currently subscribed to luau as: jmwong at hoku.net
> To unsubscribe send a blank email to $subst('Email.Unsub')
> 



More information about the LUAU mailing list