Parse ifconfig to get only my IP address using Bash

awk, bash, ifconfig, macos

Solution

Well, after hours of struggling I finally got it right:

ifconfig en1 | awk '{ print $2}' | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"

That last part I had missing is just grep a pattern of IP addresses from my list.

Problem

I want to edit the bashrc file to have a simple function called "myip" to run. As you might guess, the function myip prints only my internal IP address of my machine. The far as I got working, this is the script: ``` ifconfig en1 | awk '{ print $2}' | sort ``` Which got my this output: ``` 10.0.0.12 options=1<PERFORMNUD> flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> fe80::daa2:5eff:fe96:ba2f%en1 d8:a2:5e:96:ba:2f autoselect active ``` I'm working on Mac OS X. How can I get this done?

Original source

Related problems