Thursday, May 9, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1615  / 2 Years ago, tue, june 28, 2022, 1:54:19

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: ../../../profileone
String 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.


More From » command-line

 Answers
4

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' *.fileExtension

Note 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

[#1543] Wednesday, June 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stantildlike

Total Points: 363
Total Questions: 135
Total Answers: 120

Location: Pitcairn Islands
Member since Fri, Dec 17, 2021
2 Years ago
stantildlike questions
;