Below grep command can be used to extract IP addresses from a file.
To extract IP addresses from command output below grep command can be used.
For example, below is grep command to extract IP addresses from "ip addr" command output.
Below is sample output of above command.
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.
10.10.10.137
10.20.11.12
10.20.11.12
Products to which Article Applies
All Linux Operating SystemsAdditional Reference
https://www.shellhacks.com/regex-find-ip-addresses-file-grep/
tarun boyella
No comments:
Post a Comment