I am struggling to replace a string with a special character. I am using the command below and I tried to escape each special character, but I am still getting an error.
If I don't use special characters, the query is working fine, but I have to use special characters.
String to find: ../../../profileoneString to Replace: @mysettings/future-system-one
Query:
sed -i s/"../../../profileone"/"@mysettings/future-system-one"/g *.fileExtension'I wanted to try this command from jenkins pipeline.
22 Answers
You don't actually have any special characters there, so you don't need to escape anything. The only issue is that you are using / as the pattern delimiter, so just use another character and it should work fine:
sed 's|../../../profileone|@mysettings/future-system-one|g' *.fileExtensionNote how the sed command is quoted, that is important.
Now, your question shows the target strings as ../../../profileone and @mysettings/future-system-one, but your command also includes double quotes. If those are supposed to be part of the strings, use this instead:
sed 's|"../../../profileone"|"@mysettings/future-system-one"|g' *.fileExtension Following the comment by @steeldriver, you can change the pattern delimiters
from / to _:
sed -i s_"../../../profileone"_"@mysettings/future-system-one"_g *.fileExtension'so that you don't need to escape all the / in this way:
sed -i s/"..\/..\/..\/profileone"/"@mysettings\/future-system-one"/g *.fileExtension' 1