匹配本机IP的N种方法,以下方法仅在RedHat和Ubuntu下测试通过
+------------------------------------------------------------------------------------------------+
ifconfig | awk -F " +|:" '/Bcast/ { print $4 }'
-------------------------------------------------------------------------------------
ifconfig | awk -F "[ ]+|:" 'FNR==2 { print $4 }'
-------------------------------------------------------------------------------------
ifconfig | grep 'Bcast' | awk -F "[ ]+|:" '{ print $4 }'
-------------------------------------------------------------------------------------
ifconfig | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -1
-------------------------------------------------------------------------------------
ifconfig | grep 'Bcast' | column -s ":" -t | awk '{ print $3}'
-------------------------------------------------------------------------------------
ifconfig | sed -n '/Bcast/ { s/:/ /g; p }' | awk '{ print $3 }'
-------------------------------------------------------------------------------------
ifconfig | grep 'Bcast' | sed 's/^[ \t]*//; s/:/ /g' | cut -d " " -f 3
-------------------------------------------------------------------------------------
ifconfig | grep 'Bcast' | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | sed 1q
-------------------------------------------------------------------------------------
ifconfig | sed -n '/Bcast/ { s/[^:]*:\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/; p }'
-------------------------------------------------------------------------------------
ifconfig | sed -n '/Bcast/p' | sed 's/.*addr:\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*||\).*/\1/'
-------------------------------------------------------------------------------------
ifconfig | grep 'Bcast' | column -s ":" -t | sed 's/.*addr[ ]*\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/'