RegEx : Find IP Addresses in a File Using Grep
Here are some regular expressions that will help you to perform a validation and to extract all matched IP addresses from a file.
The following regular expressions match IPv4 addresses.
Matched IP addresses can be extracted from a file using grep command.
In this article you'll find a regular expressions themselves and an example of how to extract matched IP addresses from a file with the grep command.
Regular Expression to Match IP Addresses
Use the following regular expression to match IPv4 addresses (actually it matches all expressions from
Grep IP Addresses
Parse a file and print all expressions that match a range between
This regular expression is quite simple but you should understand that not all matches are technically valid IP addresses.
Let's find only valid IP addresses with the second regular expression.
Match only Valid IPv4 Addresses
Use the following regular expression to find and validate the IPv4 addresses :
Grep Only Valid IP Addresses
Find and extract only valid IP addresses from a file :
|-E, --extended-regexp||Use extended regular expression|
|-o, --only-matching||Print IP addresses only|