0

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
1
  • 1
    Isn't this a question for stack overflow?
    – Weboide
    Mar 22, 2011 at 15:23

2 Answers 2

2

Here's a naïve solution:

sed -i -e "s#rmi\\\\://[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+#$host_ip#"
0
1

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.

5
  • yea thats would be good idea to write application.properties from scratch :))),, thanks 4 your replay
    – moata_u
    Mar 23, 2011 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, 2011 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, 2011 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, 2011 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, 2011 at 19:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .