I have a string that goes like this abcd'efgh\ ijkl\ mnop
I want to make the string into abcd\'efgh\ ijkl\ mnop
sed 's/\'/\\\'/g
didn't work
I have a string that goes like this abcd'efgh\ ijkl\ mnop
I want to make the string into abcd\'efgh\ ijkl\ mnop
sed 's/\'/\\\'/g
didn't work
You can use
sed 's/'"'"'/\\&/g'
See the online demo:
#!/bin/bash
s="abcd'"'efgh\ ijkl\ mnop'
sed 's/'"'"'/\\&/g' <<< "$s"
# => abcd\'efgh\ ijkl\ mnop