Two things:
First, there is a difference between -e
and -E
: -e
just says "the next thing is an expression", while -E
says: "use extended regular expressions". Depending on the exact version of grep you are using, you need -E
to get things to work properly.
Second, as was pointed out before, -d
isn't recognized by all versions of grep. I found that the following worked: since ip addresses are "conventional" numbers, we don't need anything more fancy than [0-9]
to find them:
ifconfig | grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}'
No need to escape other characters (in my version of grep - using OSX 10.7.5)
Incidentally, when testing your regular expression you can consider using something like
echo "10.1.15.123" | grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}'
to confirm that your regex is working - regardless of the exact output of ifconfig
. It breaks the problem into two smaller problems, which is usually a good strategy.