Kazimieras Aliulis Kazimieras Aliulis - 1 month ago 4x
Linux Question

How do you extract IP addresses from files using a regex in a linux shell?

How to extract a text part by regexp in linux shell? Lets say, I have file where in every line is an IP address, but in different position. What is the most simple way to extract those IP addresses using common unix command-line tools?


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