Search code examples
regexlinuxbashunixcommand-line

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 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?


Solution

  • 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