Grep and Filter IP Address In Linux – POFTUT

Grep and Filter IP Address In Linux

Searching IP address in a text file or a console output may become cumbersome. This little command named grep will help you in this way.

Example Data

We have a file or output which includes IP address and we want to extract just IP addresses nothing other. This file is created with a nmap scan.

Print Interfaces IP Addresses

We can use ip addr command which will print current system interfaces and related information. We can grep from this information and print only IP addresses currently the system is using with the following command.

Print Interfaces IP Addresses

Print Interfaces IP Addresses

Print Only IP Addresses

Here we use <a href="https://www.poftut.com/exclude-grep-linux/" target="_blank" rel="noopener noreferrer">grep</a> command and give -o option to only get the IP address. The default behavior of the grep is printing lines which match given regex but if we only want to print matched text not the whole line we will use -o option which will print only IP addresses.

 

Grep and Filter IP Address In Linux Infografic

Grep and Filter IP Address In Linux Infografic

Grep and Filter IP Address In Linux Infografic

LEARN MORE  How To Get Host Name and Domain Name Of Linux?

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)