Help with shell script filtering IPs

Hello gentlemen.
I would like to create a shell script (no perl or python please) to generate a list with those rules.

Let's suppose I've this text file:

 a@A:soss(z)1.1.1.1
Opt!o:2.1.9.55
Azxk<ji>rC211.111.9.0-251.11.34.9
  d=211.9.1.3
                  O.Oox 2.1.2.4-51.9.1.33
���11.9.1.9

I would like to retain only numeric ips, here is the final output I would like to obtain:

1.1.1.1
2.1.9.55
211.111.9.0-251.11.34.9
211.9.1.3
2.1.2.4-51.9.1.33
11.9.1.9

Notes:
1) all '-' s between the Ips are valid and i want to retain them;
2) the list is pretty long (~10mb)
3) sorting and dupes are not important

Can someone help me?

Check if your grep has the -o option (what is your OS?). If so, you could try:

grep -Eo '([0-9]+\.){3}[0-9]+(-([0-9]+\.){3}[0-9]+)?' file

Apparently works but it removes a lot of valid 'entries': I've removed manually all the entries by myself and the final list is around 14mb. With your grep command the output file is arount 7.8mb (which means half valid entries are removed).

Can you provide examples of valid entries that are removed?

Found a couple of lines that has been removed:

38.101.48.170 TEXT HERE:38.101.48.0-38.101.48.255
Erie Eoege e Eeeel:146.20.0.0-146.20.255.255

When I use that with the grep statement, I get:

38.101.48.170
38.101.48.0-38.101.48.255
146.20.0.0-146.20.255.255

What do you get?

You are right, those lines are infact intact. I'm still in the process of checking what happened... it's not easy to check a 15mb text file... :frowning:
Edit: it works, my fault. Thanks so much for help.