How to grep for IP addresses using the GNU egrep utility

This is an useful regular expression if you're looking for IP addresses:

egrep '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'

Related:
How to sort IP addresses using the GNU sort utility

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

With the current egrep

With the current egrep expression, wrong IP addresses with alphanumeric characters in the last byte such as 192.168.1.3Z will match. To solve this problem out, you have to add $ at end of egrep expression, i.e: egrep '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}$'

Cheers.