sed -i '/kokomaster/!s/master/koko&/' file
First test whether the string
kokomaster exists on the line, and if it doesn't, do the substitution. This is almost a literal translation of "but what we want is to add the
koko word only if
koko not exists before
master word" into
& in the replacement part of the substitution will be replaced by the text matched by the pattern part (i.e.
After reading the comments (see below), you may want to use something more specific that would actually only modify the server name portion of the URI, and not any
master string elsewhere, even if
kokomaster occurred (or not) in the URI path:
sed -i 's,^\(discovery\.uri=http://\)\(master\),\1koko\2,' file
You may even want to go as far as matching the exact and full line that you'd want to replace, just to avoid even hypothetical mistakes:
sed -i 's,^\(discovery\.uri=http://\)\(master\.navada\.com:8800\)$,\1koko\2,' file
If the configuration file is written in JSON or some other well know format, you would not use
sed at all, but
jq or some other apropriate tool specifically written for handling files of that format.