-->

BASH: Extract only IP Address from ip addr command

Hello ,

You can use below shell script to extract only IP address from ip command.

Command :  ip addr show  | grep -oP 'inet \K[^/]+'

Example:

[root@server cgi-bin]# ip addr show  | grep -oP 'inet \K[^/]+'
127.0.0.1
10.0.2.15
192.168.56.102


Note: If you are trying to use ip command in cron jobs, please use as /sbin/ip 



Hope it helps  you. 

Share on Google Plus

About RAJA SEKHAR REDDY GENUPULA

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.