Skip to content

Instantly share code, notes, and snippets.

@mosuka
Created February 26, 2016 05:40
Show Gist options
  • Save mosuka/371ae5ba9f164def8eb8 to your computer and use it in GitHub Desktop.
Save mosuka/371ae5ba9f164def8eb8 to your computer and use it in GitHub Desktop.
Extract IP address from ifconfig command.
ip addr show | grep -e "inet[^6]" |\
sed -e "s/.*inet[^6][^0-9]*\([0-9.]*\)[^0-9]*.*/\1/" |\
grep -v "^127\."
@marshki
Copy link

marshki commented Jan 8, 2023

Of possible interest:

ip addr show |awk '/eth[0,1,2,3]/ && /inet/ {print $2}'

Sample output:

172.22.114.159/23
169.254.84.242/16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment