How to get an output formatted as "Interface: IP Address" from ifconfig on Mac
grep, ifconfig, macos, regex
Solution
This works on FreeBSD, which is at the heart of an apple :-)
#!/bin/sh
for i in $(ifconfig -l); do
case $i in
(lo0)
;;
(*)
set -- $(ifconfig $i | grep "inet [1-9]")
if test $# -gt 1; then
echo $i: $2
fi
esac
done
Problem
I am trying to get the following formatted output out of ifconfig: ``` en0: 10.52.30.105 en1: 10.52.164.63 ``` I've been able to at least figure out how to get just the IP addresses (weeding out localhost) with the following command, but it's not sufficient for my requirements: ``` ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}' ``` Thanks!