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.
999.999.999.999
too. – cYrus Oct 24 '10 at 12:11192.1.4097
are valid and accepted by Linux glibc and Windows. – user1686 Oct 24 '10 at 14:49ping 2130706433
, on OS X:PING 2130706433 (127.0.0.1): 56 data bytes
. – Arjan Oct 24 '10 at 15:150x7f.1
and0177.1
– user1686 Nov 7 '10 at 10:23