The following is working as expected. I want to replace the word “me” with \’
echo "test ' this" | sed 's/'"'"'/me/g'
test me this
Expected result:
test \' this
Is it possible to escape double quotes as well in the same command?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your question is a little confusing since there’s no
mein the original string to replace. However, I think I have it. Let me paraphrase:If that’s the case (you just want to escape single quotes), you can use:
By using double quotes around the
sedcommand, you remove the need to worry about embedded single quotes. You do have to then worry about escaping since the shell will absorb one level of escapes so thatsedwill see:which will convert
'into\'as desired.If you want a way to escape both single and double quotes with a single
sed, it’s probably easiest to provide multiple commands tosedso you can use the alternate quotes:If I’ve misunderstood your requirements, a few examples might help.