Though you still need to escape the '\' to stop sed misinterpreting it, you won't need to escape ⦠As we see, we can use \ to escape / to include a / when / is the delimiter. In computer programming, leaning toothpick syndrome (LTS) is the situation in which a quoted expression becomes unreadable because it contains a large number of escape characters, usually backslashes ("\"), to avoid delimiter collision.. If you want the replace some occurences of a URL in a file the sed command looks really ugly because you have to escape every slash "/" with a backslash "\" To make it look a lot cleaner you could just change the delimiter used by sed: Special meanings of certain escaped characters. Because the regexp is delimited by slashes, you need to escape any slash that is part of the pattern, in order to tell awk to keep processing the rest of the regexp. Properly escaping forward slash in bash script for usage with sed Helpful? I was editing a file and found accidentally that I somehow escaped all the forward slashes in a path I was replacing in text. means return \t. sed can also use a regular expression to find matches. In this particular case, the Apache configuration file has lines with #âs not at the beginning of some lines, ... Another use of sed consists in printing the lines from a file that match a given regular expression. used with echo and sed \n. To use a comma instead of a slash, use: sed '\,^#, s/[0-9][0-9]*//' The main advantage of this feature is searching for slashes. Regular-expression matches Example echo -e 'find fend found' | sed 's/f.nd/replace/g' Output replace replace found Explanation. Because when youâre writing a JSON string, if thereâs a backslash in the string, you have to escape it by prefixing with another backslash. For instance, to do this replacement correctly I should escape the second path: And that is something very useful! The vertical bars indicate boolean operations, whereas the backward slash is used to escape the vertical bars. means newline \r. Linux Bash->SED compatible online escape character tool v.1.3. Put into Input Box the character sequence you want to escape: Input: Output: ESCPAE. You need two \\ because \ is an escape character. If the expression starts with a backslash, the next character is the delimiter. \" A literal double quote (should be used for string constants only). ⦠But I'll discuss those later. Why do we care about the escaping backslash in JSON? The same command run in shell works without any errors. If you want to edit the file, add -i: sed -i 's/ / \\ /' hw The command replaces the space by space\space. For example, the following sed command emphasizes every word: Below is the init container I am using, I need to use sed to modify on the fly one parameter, when I run kubectl create -f container.yaml I see this error: kubectl create -f tgtd-pod-v2.yaml unable to decode "tgtd-pod-v2.yaml": invalid character '(' in string escape code. If you have a file named hw containing Hello World, the sed command would be: sed 's/ / \\ /' hw This displays the wanted result on the screen. Sed does provide a few extra options when specifying regular expressions. Explanation: Sometimes it's really tricky and ugly (the output) to manually escape a character sequences in allready escaped stuff in database. If you need to use sed because you're doing something more complex than that, then a little known tip is that you can actually use other delimiters to make it more readable. With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect - it can toggle on a special meaning for that character.