0

I am trying to replace a string with another string in files that are present in subdirectories of a directory.

Below are the string values

old_string = gs://common/jars/sap_njdbc_2.12.jar
new_string = ${path_to_jar_file}

I have tried like below

find ./ -type f -exec sed -i 's/gs://common/jars/sap_njdbc_2.12.jar/${path_to_jar_file}/g' {} \;

I am getting a error like below

sed: -e expression #1, char 3: unterminated `s' command

How do I achieve my correct result

nmr
  • 605
  • 6
  • 20
  • 1
    you can't use `s/pattern/replacement/` syntax if the pattern has `/` in it. Instead do `sed -i -e `s#pattern#replacement#g` . `-e` supports arbitrary delimiters. – erik258 Jul 29 '23 at 14:51

2 Answers2

2

Change your command to like below. It will work

find ./ -type f -exec sed -i 's|gs://common/jars/sap_njdbc_2.12.jar|${path_to_jar_file}|g' {} \;

As you are using / in your pattern it will not work. So replace / with some other delimiter like |.

David Ranieri
  • 39,972
  • 7
  • 52
  • 94
User12345
  • 5,180
  • 14
  • 58
  • 105
0

Couple of issues that I can see off the bat:

  • You didn't properly escape the forward slashes in your replacement string.
  • Your ${path_to_jar_file} was contained in single quotes, you have to use " double quotes.

Try this:

find ./ -type f -exec sed -i "s/gs:\/\/common\/jars\/sap_njdbc_2.12.jar/\$path_to_jar_file/g" {} \;

Granted, this is for if you are wanting to use the literal ${path_to_jar_file} as your question was a little unclear. Let me know if that works for you.