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?
It's hard to escape a single quote within single quotes. Try this:
Example:
produces
You need to use \" for escaping " character (\ escape the following character
May be the "\" char, try this one:
My problem was that I needed to have the
""
outside the expression since I have a dynamic variable inside the sed expression itself. So than the actual solution is that one from lenn jackman that you replace the"
inside the sed regex with[\"]
.So my complete bash is:
Here is:
#
is the sed separator[\"]
="
in regexvalue =
\"tags/$RELEASE_VERSION\"
= my replacement string, important it has just the\"
for the quotesThe
sed
command allows you to use other characters instead of/
as the delimiter in itss
command:The double quotes are not a problem. For matching single quotes, switch the two types of quotes around. Note that a single quoted string may not contain single quotes (not even escaped ones).
The dots need to be escaped if
sed
is to interpret them as dots and not as the regular expression pattern.
which matches any one character.