0

File: abc.properties

tomcat.home=/opt/tomcat

Set to /usr/local/tomcat. Following cmd is working.

sed -i "/tomcat.home=/ s/=.*/="usr\\/local\\/tomcat"/" abc.properties

Set to $WORKSPACE/tomcat. Following cmd is NOT working since value of the $WORKSPACE is having / delimeters.

sed -i "/tomcat.home=/ s/=.*/="$WORKSPACE\\/tomcat"/" abc.properties

Anyone has an idea how to success above cmd.

Thank you and appreciate your support...

user3332279
  • 59
  • 1
  • 10

1 Answers1

1

Sed lets you use any character you want as the delimiter. Whatever follows the s is used as the separator:

sed -Ee 's/foo/bar/'
sed -Ee 's|foo|bar|'
sed -Ee 's@foo@bar@'

^- All of those are equivalent.

The other option is to escape all your / as \/, but that gets nightmarish fast. Prefer to just pick a separator character that doesn't collide with characters you're trying to use for something else.

Chris Kitching
  • 2,559
  • 23
  • 37
  • The routine use of `-E` is misdirected here (the regular expressions don't contain anything where it would matter) and is not portable (some `sed` variants use `-r` instead, some don't support it at all). – tripleee Feb 16 '18 at 06:12
  • If you have no control over the input, finding a separator character which cannot occur in the input is much more nightmarish than figuring out how to properly escape the separator in the value. If you have Bash, `${variable//\/\\/}` obscurely but conveniently obtains the value of `variable` with slashes backslash-escaped. (Though for complete coverage, you should also backslash-escape any backslashes.) – tripleee Feb 16 '18 at 06:13
  • It solved my problem & Thanks a lot... – user3332279 Feb 16 '18 at 07:00