regexsedcmder

Replacing special characters using sed within windows cmder....and getting an strange error with url parameter


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%202021%20donutshop%20lifestyle&utm_content=primary%20cta&brand=Donut%20Shop&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.


Solution

  • You need to use

    So you need to use

    sed -i "s|category=2fLShbTEL0cKrSR7J9S2hk&emailRedirect=Y|utm_source=marketingcloud\&utm_medium=email\&utm_campaign=p8%202021%20donutshop%20lifestyle\&utm_content=primary%20cta\&brand=Donut%20Shop\&emailRedirect=Y|gi" *.html