Below grep command can be used to extract IP addresses from a file.
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' <filename>
To extract IP addresses from command output below grep command can be used.
<command> | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
For example, below is grep command to extract IP addresses from "ip addr" command output.
ip addr | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
Below is sample output of above command.
Products to which Article Applies
All Linux Operating Systems
Additional Reference
https://www.shellhacks.com/regex-find-ip-addresses-file-grep/