Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

rmi.sceduling.service.url=rmi\://192.168.0.19\:1199/ScedulingService

The code should also work if there is no address:

rmi.sceduling.service.url=

It should also be portable, at least to Solaris.

The code I am using at the moment:

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

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

2 Answers 2

up vote 1 down vote accepted

A portable solution that should work on both solaris and ubuntu

ed -s application.properties << EOF
  g/=rmi\\\\:\/\/[^\]*/s||=rmi\\\\://$host_ip|
  w
EOF

Why are you doing all these edits (in this and several of your other recent questions) on this application.properties 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 application.properties 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
    
@geirha..in 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

 
discard

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.