I read on a post that when using sed -i in order to replace values containing special characters in becomes necessary to use '|' instead of '/' which works when replacing simple text words.
Eg: sed -i 's|'$original_value'|'$new_value'|g'
where original_value="comprising_special_char_/" new_value="comprising_new_special_char:
I have tried this with shorter less complex strings and it works fine but I'm getting an error message when I attempt this with the following strings.
sed -i 's|'category=2fLShbTEL0cKrSR7J9S2hk&emailRedirect=Y'|'utm_source=marketingcloud&utm_medium=email&utm_campaign=p8 2021 donutshop lifestyle&utm_content=primary cta&brand=Donut Shop&emailRedirect=Y'|gi' *.html
Can anyone provide help as to why I get the error shown below when running the above command in windows cmder (which uses gnu)?
''category' is not recognized as an internal or external command, operable program or batch file.
CodePudding user response:
You need to use
- Double quotation marks around the sed command
- Escape
&
chars in the replacement only.
So you need to use
sed -i "s|category=2fLShbTEL0cKrSR7J9S2hk&emailRedirect=Y|utm_source=marketingcloud\&utm_medium=email\&utm_campaign=p8 2021 donutshop lifestyle\&utm_content=primary cta\&brand=Donut Shop\&emailRedirect=Y|gi" *.html