How to extract a text part by regexp in linux shell? Lets say, I have a file where in every line is an IP address, but on a different position. What is the simplest way to extract those IP addresses using common unix command-line tools?
In Linux you can use regular expressions with grep to extract an IP address from a file. The grep command has the -E (extended regex) option to allow it to interpret a pattern as a extended regular expression.
Get your Private IP Address with the ifconfig Command One way is to use the ifconfig command. ifconfig is a command line program that configures network interfaces on Linux.
so you can use grep -oE "\b([0-9]{1,3}\.){ 3}[0-9]{1,3}\b" to grep the ip addresses from your output. Thanks. This works.
You could use grep to pull them out.
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With