Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to change the IP address in this string with some user input:


The code should also work if there is no address:


It should also be portable, at least to Solaris.

The code I am using at the moment:

value=`grep 'rmi' \
| awk -F":" '{print $2}' \
| awk -F"\'" '{print $1}'
| cut -d '/' -f 3-5 `

sed -e "s/$value/$host_ip/g" > file.tmp \
&& mv file.tmp
share|improve this question
Isn't this a question for stack overflow? – Weboide Mar 22 '11 at 15:23
up vote 1 down vote accepted

A portable solution that should work on both solaris and ubuntu

ed -s << EOF

Why are you doing all these edits (in this and several of your other recent questions) on this file anyway? Seems to me that just writing that file from scratch would be much easier.

share|improve this answer
yea thats would be good idea to write from scratch :))),, thanks 4 your replay – moata_u Mar 23 '11 at 11:59
thanks it work perfectly ,,,well am trying doing this because i want learn shell script ...SO much hard much fast learn... – moata_u Mar 23 '11 at 12:04 terminal your script work with no any problem when i append it in my script it always telling me unexpected end of file !!! ?? – moata_u Mar 23 '11 at 12:41
The closing EOF must not be indented. There is an indented variety where you do cmd <<- EOF in which case preceding tabs (\t) will be ignored, but regular spaces will still make it fail. – geirha Mar 23 '11 at 17:48
that's right i will try figure that out ....if i find something i will post the solution .. – moata_u Mar 23 '11 at 19:13

Here's a naïve solution:

sed -i -e "s#rmi\\\\://[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+#$host_ip#"
share|improve this answer
good idea i will try it by tomorrow...thanks – moata_u Mar 22 '11 at 20:41

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.