From what I can find, when you use single quotes everything inside is considered literal. I want that for my substitution. But I also want to find a string that has single or double quotes.
For example,
sed -i 's/"http://www.fubar.com"/URL_FUBAR/g'
I want to replace "http://www.fubar.com" with URL_FUBAR. How is sed supposed to recognize my // or my double quotes?
Thanks for any help!
EDIT: Could I use s/\"http\:\/\/www\.fubar\.\com\"/URL_FUBAR/g
?
Does \ actually escape chars inside the single quotes?
Regarding the single quote, see the code below used to replace the string
let's
withlet us
:command:
result:
Escaping a double quote can absolutely be necessary in sed: for instance, if you are using double quotes in the entire sed expression (as you need to do when you want to use a shell variable).
Here's an example that touches on escaping in sed but also captures some other quoting issues in bash:
Let's say you wanted to change the room using a sed script that you can use over and over, so you variablize the input as follows:
This script will add the whole line if it isn't there, or it will simply replace (using sed) the line that is there with the text plus the value of $i.
P.S. I wrote out the script above on multiple lines to make the comments parsable but I use it as a one-liner on the command line that looks like this: