Contents
Does forward slash need to be escaped?
Some languages use / as the pattern delimiter, so yes, you need to escape it, depending on which language/context. You escape it by putting a backward slash in front of it: \/ For some languages (like PHP) you can use other characters as the delimiter and therefore you don’t need to escape it.
What does G in sed do?
In some versions of sed, the expression must be preceded by -e to indicate that an expression follows. The s stands for substitute, while the g stands for global, which means that all matching occurrences in the line would be replaced.
How do I pass forward slash in JSON?
JSON escapes the forward slash, so a hash {a: “a/b/c”} is serialized as {“a”:”a\/b\/c”} instead of {“a”:”a/b/c”} .
When do you use escaped backslash in SED?
You’d want to use the escaped backslash in cases where you don’t know what characters might occur in the replacement strings (if they are shell variables, for example). The s command can use any character as a delimiter; whatever character comes after the s is used.
How to insert strings containing slashes with SED?
So if you use sed to return some HTML templates (on a server), use double backslash instead of single:
When to use single quotes in a SED expression?
Unless you want to interpolate a shell variable into the sed expression, use single quotes for the whole expression because they cause everything between them to be interpreted as-is, including backslashes. So if you want sed to see s/\\ (127\\.0\\.1\\.1\\)\\s/\\1/ put single quotes around it and the shell won’t touch the parentheses or backslashes in it.
Do you need backslashes for SED in BrE?
If you choose a character that has a special meaning in a BRE and you want to include it literally, you’ll need three backslashes; I do not recommend this, as it may behave differently in some implementations. In a nutshell, for sed ‘s/…/…/’: