What regular expression can I use to match an IP address?
- by jennifer
With the following grep syntax I want to match all IP address in a file (from a ksh script)
grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file
The problem: It also matches words (IP) that have more then 4 octets:
1.1.1.1.1
or
192.1.1.1.160
How can I match a valid IP and only IP addresses with 4 octets? I can also use Perl – a one line syntax solution, if grep doesn't work.