Article 6N4TP [SOLVED] [BASH] grep IP address and IP with network mask in one go?

[SOLVED] [BASH] grep IP address and IP with network mask in one go?

by
czezz
from LinuxQuestions.org on (#6N4TP)
Initial file:
Code:cat file.txt
172.16.100.0/24
148.180.112.67Following grep will extract IP address only from file.txt
Code:cat file.txt | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
172.16.100.0
148.180.112.67Following grep will extract IP with its netmask only (will skip any IP address without \netmask)
Code:cat file.txt | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9][0-9]'
172.16.100.0/24I was trying to combine both adding -E flag but that wont work:
Code:cat file.txt | grep -o -E "'[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'|'[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9][0-9]'"Ofc, i can run it in to steps and then process/merge outputs.
However, i was wondering if anyone knows some clever way to have it all in one go? :)
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments