Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I need to grep to IP address ( as the following example ) , I use ksh script ,

    #  ifconfig -a |  /usr/xpg4/bin/grep   "100\.106\.2\.120 "
    inet netmask ffffff00 broadcast

but how to grep IP address from parameter ( IP_ADDRESS ) ?

  • Remark - IP address could be any IP

how to add the back slash in this case

IP_ADDRESS= , or IP_ADDRESS= ... etc

    #  ifconfig -a |  /usr/xpg4/bin/grep   "$IP_ADDRESS "
share|improve this question

1 Answer 1

up vote 3 down vote accepted

If you are using the bash shell you can Use parameter expansion:

ifconfig -a | /usr/xpg4/bin/grep "${IP_ADDRESS//./\\.}"

If your shell doesn't support this type of parameter expansion, you could use shell expansion instead, e.g. with sed:

ifconfig -a | /usr/xpg4/bin/grep `echo $IP_ADDRESS | sed 's/\./\\./g'`

or perl:

ifconfig -a | /usr/xpg4/bin/grep `echo $IP_ADDRESS | perl -pne 's/\./\\./g'`
share|improve this answer
I use the ksh shell not the bash shell – yael Feb 7 '13 at 11:43
@yael: many versions of ksh also support this type of parameter expansion. – Thor Feb 7 '13 at 11:46
my ksh not support it - # ifconfig -a | /usr/xpg4/bin/grep "${IP_ADDRESS//./\\.}" ksh: "${IP_ADDRESS//./\\.}": bad substitution – yael Feb 7 '13 at 11:47
@yael: alternatively you could use shell expansion, see edit. – Thor Feb 7 '13 at 17:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.