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[^/]+'


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

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

Hope it helps  you.