regex help needed

Anderson Lizardo lizardo at linuxfromscratch.org
Sat Oct 16 08:19:07 PDT 2004


On Thursday 14 October 2004 22:13, Bennett Todd wrote:
> 2004-10-14T23:10:01 John Galbrit:
> > How would I grep logfiles to search for all IP addresses?
>
> There are _lots_ of answers. Here's mine:
>
> grep '[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*' filename

It seems to exclude valid IPs like 127.0.0.1. Is that the desired effect?

Now my suggestion :)

egrep -o '[0-9]{1,3}(\.[0-9]{1,3}){3}' filename

As you can see, it limits the number of algarisms of each field to 3, reducing 
the number of false positives (but not eliminating them, as it matches 
invalid IPs like 999.999.999.999).

-- 
Anderson Lizardo
lizardo at linuxfromscratch.org
http://www.linuxfromscratch.org/



More information about the lfs-chat mailing list