Q:

extracting ip address from a file

I'm trying to extract all the IP address from a file.
FILE
*>i85.95.2.160/29   172.16.24.4              0    200      0 64515 4445 15412 i
*>i85.112.80.0/28   172.16.24.4              0    200      0 6774 64521 i
*>i85.112.80.96/27  172.16.24.4              0    200      0 6774 64521 i
*>i85.115.64.96/27  172.16.24.4              0    200      0 2300 64961 i

OUTPUT
85.95.2.160
85.112.80.0
85.112.80.96
85.115.64.96

This is what I have so far:
$ awk < ips '{ print $1 }' grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' ips | sort | uniq

The problem is that from the list of IP addresses it goes from the beginning up to:
84.241.254.8/29

It does not extract any of the following ip addresses:
84.241.254.32
85.115.240.0
91.232.100.72
103.248.251.48
121.58.160.79
160.218.26.16
200.6.224.96
223.255.231.240

Any ideas why these aren't getting extracted?

A:

This is a more accurate regex for matching an IPv4 address:

(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)

It will place each octet into its own capture group. If you don't want that, then this following one captures the full address into a single capture group:

((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)

Having said that, I don't think the problem is your regex.
By the way, this should be a comment, not an answer... but it would be an extremely messy comment.

