Sed escape equal sign Basically, I used a list item with a pipe, like this: - | and then on a new line I indented the list item text so that the first character lined up with the pipe. For example, ‘\*’ matches a single asterisk rather than zero or more backslashes. 1. The special characters in my list are & []' Consider the below solution of systematically escaping the delimiter character in the input string before having it parsed by sed. Such escaping can be implemented as a replacement using sed itself, this replacement is safe even if the input string contains the delimiter - this is since the input string is not part of the sed command block: I have trouble matching this pattern <= with a regular expression in sed. Because we want the equal sign in the output, we need to substitute for all that an equal How can escape the literal string #!/bin/bash in a sed expression? Curently I have a command in a bash script of the form. If the label variable is empty, it branches to the end of the script. While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. /tmp'\'';#d' file When the regexp/replacement contains the match delimiter (usually /), it can sed -i "s/=//g" file. Email. Follow edited Apr 16, 2015 at 14:22. In a nutshell, for sed 's///': Write the regex between single quotes. Per POSIX: sed is a text processing tool and so is only expected to work on text files. cmd/. Sed needs many characters to be escaped to get their special meaning. Also, there's no need to use . I hope that helps, it worked for me in a Rails 4. Within double quotes, backslashes that are followed are removed". I actually want to edit more than one line, but this line demonstrates the problems: The command works, provided no $ signs are used within the sed command. I'm testing with the same version of sed on RHEL 6. xls In the regex ^[^=]*=/, the leading caret means that the regex has to match starting at the beginning of the line. For /F "tokens=*" %%B IN (test. . txt: sed ’s/hello/world/’ input. If used in a regular expression, it often means 'end of line' but sometimes means dollar-sign (if it is in the middle of a regular expression). These are all special characters, \\ and ‘\’ are equivalent. sed -f str-to-regex. out GNU sed processes escape sequences before passing the text onto the regular-expression matching of the s/// command and Address matching. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. tso tso. In most cases, you can use the short plugin name regex_escape. The setlocal enableDelayedExpansion should be moved after your old=%%B assignment in case %%B contains !. Basic regular expressions (BREs): A <dollar-sign> ( $) shall be an anchor when used as the last character of an entire BRE. 4. when using many implementations of regexps. 2 locale file. txt Avoid double quotes around the Groovy string, since they can lead to security issues via Injection via Interpolation, if you can't guarantee the content of your variable is safe. The problem is the Zip with the period. This makes a backup of file1 and then edits a line in the file. Step 3: Run the sed-script which converts the string into a sed regeular expression, and send its output to another sed-script, replace-text. Note that if you use such an escaped string as part of regular expression in e. . for sed or ssed, may be due to the specific programs called in the batch scripts. /check. What I really need is something like [<|<=] either or type match. Replace special character "/" using sed command. – terdon. builtin. ) Escape characters on the right side of "s///" The * This feature of sed16 and sedmod will break sed scripts which put a dollar sign and digit into the sed -e :a -e '/\\$/N; s/\\\n//; ta' file # If a line begins with an equal sign, append it to the previous # line (and replace the "=" with a single space). I can get it to work with . If they are escaped this SED command works on Mac OSX Sierra. The <dollar-sign> You can use a $$ (double-dollar sign) when your configuration needs a literal dollar sign. txt; it can be run simply as . – Do note that you need to be sure that the variable value doesn't contain percent signs, then; and if you need to insert a literal $ or a backslash in the sed command, you'll need to escape them, since the shell processes them inside backslashes. *, but this occasionally creates other problems with the rest of the line. 105u Mentioning the special characters in a single quote is an exact work around for escaping special characters but in this case as comma is present it's considered as extra-scope (Scopes to request to the provider (comma separated)). So now with GNU sed, (is a special character; just like egrep. I use brackets: sed "1,/abc[-]def/d" file1. 2 Running sed This chapter covers how to run sed. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible. As you can see, my platform uses the very same version of GNU sed as yours. tr -d '=' < file. This works as expected: >echo "a=b" | sed "s/a=//" "b" You need to escape (with backslash \) all substituted slashes / and all backslashes \ separately, so: $ echo "/tmp/test/folder1/test. For instance, \n can be used to represent a newline within a multiline string. I would like to change that period for a new line, but I cannot get it to work. The others are mostly for testing and demonstration. 0,*****,-5. *one is\(. But for ERE, you have to escape chars which have special meaning to get literal string. This command file processes each line one character at a time, treating specially the case where you find the stanza you're looking for. This filter plugin is part of ansible-core and included in all Ansible installations. Description: In addition to their use as mathematical operators, the slash and backslash characters separate the elements of a path or folder. [[:space:]] is equal to [ \t\r\n\v\f]. e. answered Sign up or log in. regex_escape for easy linking to the plugin documentation and to avoid conflicting with other collections that This was already suggested in a similar way by @tripleee, and I see no reason why it should not work. Post as a guest. I want to perform an operation with all these files so I'm trying to store all filenames in a list. For example, it would match: (without space within the tags) I want to replace all single quotes in a string with two single quotes using sed. Use -E modifier for extended regular expressions, which do. Hot Network Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site The best solution is to download and install Cygwin or GNUWin32 but, if you're really limited to the standard command processor, it can get a little messy. txt or sh check. txt data + net06706 net06707 + net221 net222 net223 m1 net10 rwl vdda vss nch l="l1pg+0. Commented Apr 1 $ sed 's/^[^=]*=/=/' everyone. SED regex match EOF and replace/insert. (Thanks, Ed Morton & Niklas Peter) Note that escaping everything is a bad idea. e + represents the plus sign as does \+ when the -E is invoked, whereas \+ and + when the -E or -r is invoked represent one or more of the preceding character/group. Something like this. If you just want the part between "one is" and "String", then you need to make the regex match the whole line: sed -e 's/. You can even use BASH string replacement: s="2006. txt if the variables are exported. To search for a $ (dollar sign) in the file named test2, enter: grep \\$ test2. First, to expand the shell variables, you need to put them in double quotes, not in single I am working in bash, and would like replace a string with escaped special characters: echo No need to pipe cat to sed: $ sed 's/<a href="\/tag\//<a href="http:\/\/www. 2. This can ve done with a sed command, but the problem is that the file, which you say it is autogenerated, is wrongly generated. Remove the percentage sign; You only need to escape the slash; I would like to be able to use a sed command that matches for the equal character and do so from a shell script. mydomain. Extended Regex with using -E is much more familiar Like forward slash, dollar sign, singe dot , – Soumali Chatterjee. txt) DO ( SET t=is SET old=%%B SETLOCAL ENABLEDELAYEDEXPANSION for /f %%T in ("!t!") do SET new=!old:%%T=! Stack Exchange Network. ini [server] hostname=AABB we want to match hostname word in file and replace only the value after = ( equals character ) so we did that VAR= I don't like the escaping with normal sed. – What you're doing is the correct way: [is always supposed to be an ordinary character in sed y///. sed -e :a -e '$!N In Sed's specification, s command:. If you use it in awk '/regex/' , you would have to escape / character in regex. Please edit your question and show us your expected output so we can be sure we are giving you what you expect. 1 Overview Normally sedis invoked like this: sed SCRIPT INPUTFILE For example, to replace all occurrences of ‘hello’ to ‘world’ in the fileinput. With 0 or 1 address or at the end of a 2-address range, places the Text variable in output and then starts the next cycle. sed, which will make the actual replacement. ) $ Match the last line. How can I escape the & character so that the single quotes after it Percent Sign % % can be escaped as %% – "May not always be required [to be escaped] in doublequoted strings, just try individual programs are responsible for parsing their command line arguments so some of the escaping required for, e. The command that I use is: sed -E -f scrub. As an alternative, you can use the -r or --regexp-extended option to use the "extended regular expression syntax", which reverses the meaning of escaped and non-escaped special first can be zero; in this case, sed operates as if it were equal to step. remove + and append that line to previous line. But it is sed’s ability to filter text in a pipeline which I am tired of always trying to guess, if I should escape special characters like '()[]{}|' etc. Substitute the replacement string for instances of the BRE in the pattern space. Many newer implementations of regular expressions, including egrep and perl, switched this around, so \(meant a literal open-paren, and (was used to specify grouping. Clearly my answer obviously didn't solve his problem, but I don't think adding empty quotes is the answer, especially if they're passed as an individual parameter. I'm looking to match all less than ('<') or greater than ('>') signs in a file using sed. txt sed: -e expression #1, char 18: unterminated `s' command You might be able to use this technique to protect the selector. sed script is as follows: Description. This chapter introduces another kind of escape 6 —that is, escapes that Backslash works fine. Visit Stack Exchange 1 Introduction. Also, I believe the empty quotes should be attached to the -i option or be used with = in the long parameter. txt > file2. sedコマンドでの置換対象文字列にやたらと特殊文字が含まれている場合にめちゃめちゃハマったのでメモを残す。 注目すべきは以下3点。 sedコマンドの引数は特殊文字3種($`\)以外をエスケープするダブルクォートを使用すること Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand; OverflowAI GenAI features for Teams; OverflowAPI Train & fine-tune LLMs; Labs The future of collective knowledge sharing; About the company Perhaps the closest to a standard, the POSIX/IEEE Open Group Base Specification says: [2addr] s/BRE/replacement/flags. The + must be escaped in the regex because with sed's regex engine + is a normal character whereas \+ is a metacharacter for 'one or more'. *$/= your-replacement/' TheFile /^power / is an address specifier, in this case looking for a line that matches a regex ^power. 8 Escape Sequences - specifying special characters. Note that there is no need to pipe the contents of the file; you can just specify it (or a list of files) as a command argument. sed 's! !\\ !g' prefixedfiles. Originally sed, like grep and everything else, used \(to indicate grouping, whereas (just matched a literal open-paren. 3. 3 Double Quotes, "The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘"’, ‘\’, or ‘newline’. I'm having a directory with many files having special characters and spaces. 2,589 8 8 gold badges 26 26 silver badges 42 42 bronze badges. The expression [^=]*= matches every character up to and including the first equal sign. cpp If you're in a shell, you might need to double escape $, since it's a special character both for the shell Consider that escape caracter is \ not / EDIT. We will always use sed with the -r flag. First of all, sed uses basic regular expressions by default, which do not recognise +. The implementation may treat a <dollar-sign> as an anchor when used as the last character of a subexpression. txt and then run the command with this list. I assume that he felt the same way about the plus sign, hence the need to escape it to use it as a I understand. *\)String. (2)c\Text Deletes the pattern space. trail. This is not the fastest method in the world but it's at least functional. (2)b[label] Branches to the : command bearing the label variable. For sed, BRE syntax in info sed use '\$' for a single dollar sign. For example, the following command replaces the words ‘gray’ or ‘grey’ with ‘blue’: With Bash and SED I'm trying to replace two strings in a js file with URL's. txt D:\usr Your original command $ sed 's!\\usr!${path}/g;' test. command I'm am trying to replace a series of asterix symbols in a text file with a -999. The sed stream editor performs basic text transformations on an input stream (a file, or input from a pipeline). +1 for thinking out of the box - but not helping him learn how to use sed properly. My goal is to replace them with ' <' and '> ' (ensure they have white space around them so I can parse them easier) respectively. /regexp/ Match lines matching the regular expression regexp. If grep is a fancy “find” of the command line, sed (stands for stream editor) is the “find-and-replace” of the command line. POSIX has this to say about the difference in how $ is interpreted in basic and extended regular expressions:. sed test. 0 * is a regex symbol that needs to be escaped. txt, which contains spice netlist. 335. In order to get a literal ampersand, you will have to escape it: 5. " Share. The + is a repeat operator, and since sed is using BRE (basic regular expression) syntax it has to be escaped. However I can't figure out how to properly escape the wildcard symbol. You only have to enclose any values you would be referencing like {@field1}. It matches any single character in that list; if the first character of the list is the caret ‘^’, then it matches any character not in the list. The lines marked with "*****" below are the significant lines. txt Backreferences only match the exact same characters as before; the above example does not match any three-letter word followed by a space and then another three-letter word. But it is sed's ability to filter text in a pipeline which particularly 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). Thus the follwing two commands are What characters do I need to escape when using sed in a sh script? Two things here. I use a numerical literal: sed "1,/abc\D2def/d" file1. 0,1. The key is to use a character that doesn't appear in the user input to delimit the selector address. Commented Jul 25, 2017 at 7:54. Now I want to replace all expanded parameters to one line only i. Commented There are several problems. Second, sed doesn't recognise \n; but you can use ANSI C quoting to make bash understand it. Modified 3 years, I know I can handle these exact two escape sequences by piping to sed and matching those exact two sequences, Sign up using Email and Password Submit. ‘ [^ tab]\+ ’ (Here tab stands for a single tab character. How does sed know what What I want to do is to be able to replace part of the string of each line with an equal sign using sed. Note: this started as an answer to How to pass special character string to sed hence the $_REQUEST['old'] strings, however this question is a bit more appropriately formulated. In sed, you need to escape the dollar sign, because otherwise it means "anchor to the end of the line. For example, if you escape a digit in the replacement string, it will turn in to a backreference. The meaning of an unescaped backslash immediately followed by any character other than '&', backslash, a digit, newline, or the delimiter character used for this command, is unspecified. Name. Note. – Dinerdo. A bracket expression is a list of characters enclosed by ‘[’ and ‘]’. echo '*. Note I only want to replace the first comma , , ie. txt > output. bat command-script, you only need to consider sed's escape-character which is a backslash \ They are two quite seperate scopes (which can overlap, so it is often Before posting my question, I used google I found an answer. g. It also means \ and / are both considered valid directory separators for the How about: sed '/^power /s/=. ]\+[0-9] to make sure that the first and last character is not a dot. So, when I tried with escaping & in my input as follows, it actually works: sh password_replace. Using standard sed: sed 's/^\(MY_VAR\)[[:blank:]] sed: escaped square closing bracket does not match. sed 's_\s_\\&_g' This substitutes every (g) whitespace character (\s, matches spaces, tabs and newlines embedded in the pattern/hold spaces) in every line with a backslash (\\) and If your intent is to only change paths that have that specific directory, you need to be a bit trickier. If you want to avoid matching dots on ends, like 1. txt is still better than cat file. I only want to match the single character. The only difference to @tripleee's version is that I use the extended regex mode, so I have to either escape the pipe and the plus or put it into a character class with []. ‘ \$ ’ Instead, this matches a string consisting of a single dollar sign, because it is escaped. Check out all the stuff you can do with it. txt. With the sed command, you can edit text in files and streams on Linux. If the variables were merely set, then the . Instead, you can pass your variables in the shell's environment: Oct Dec Hex Char Oct Dec Hex Char ----- 000 0 00 NUL '\0' 100 64 40 @ 001 1 01 SOH (start of heading) 101 65 41 A 002 2 02 STX (start of text) 102 66 42 B 003 3 03 ETX (end of text) 103 67 43 C 004 4 04 EOT (end of transmission) 104 68 44 D 005 5 05 ENQ (enquiry) 105 69 45 E 006 6 06 ACK (acknowledge) 106 70 46 F 007 7 07 BEL '\a' (bell) 107 71 47 G 010 8 Name: Slash and Backslash. Jeff Schaller. making it looks like this 2nd Monday=2019-01-14,2019-02-11, It seems as if the only blanks that you need to match are the ones between the variable name and the equal sign. On Microsoft ® Windows ® based systems, both slash and backslash have the Assuming your path variable was assigned properly (without spaces in the assignment: path='first\usr'), fixing step by step for an input file test. pls = foo. You should fix the root, rather than treat the symptoms. 2. txt with one example path: $ cat test. sed is a stream editor. Improve this answer. Forest & amp; Paper Products Manufacturing Can't figure out why sed is putting a space after the & I can solve this with: sed "s/ \& / \& /" But why do I need to quote the & with a \ prefix I have trail. It is different with, for example, Python, sed, grep, awk, In another question from you, I mentioned, for BRE, you have to escape those chars to give them special meaning. in > file. Matching is performed on the current pattern The $ sign has different meanings depending on where and how it is used. $ echo "2006. 0" echo "${s Just use awk so you don't spend the rest of your life figuring out which characters you need to escape in which contexts using sed - it's an unsolvable problem and the solutions' trivial in awk and you don't need the cat and multiple pipes either: [[:space:]] doesn’t match just spaces but rather all whitespace characters including tabs and line breaks. The general syntax looks like That's not NULL (a string), it's NUL (a character). But you don't want to catch things like /var/lib/mysqlplus since that's a totally different directory. Use '\'' to end up with a single quote in the regex. But for your specific case, lnian's answer is spot on. $ echo "seab'cd" | sed 's/b'\''c/foo/' seafood $ echo "seab'cd" | sed "s/b'c/foo/" seafood Note that if you use the second (double quotes) version then you're allowing shell This might work for you (GNU sed): sed -i '\#\$settings\['\''file_temp_path'\''\] = '\''\. com\/tag\//g' wordpress_posts. Note how, in the case of text2, the <dollar-sign> is escaped, losing its special functions and preserving its literal meaning. This is different from tr where [can be part of a character class like [:alpha:]. ‘ [a-zA-Z0-9] ’ In the C locale, this matches any ASCII letters or digits. If used as a 'line number', it means 'the last line'. The accepted answer suggests sed -i and describes it as replacing the file in-place, but -i doesn't really do that and instead does the equivalent of sed pattern file > tmp; mv tmp file, preserving ownership and modes. txt" | sed 's/\//\\\//g' \/tmp\/test\/folder1\/test. Note that ^^ for ^, and ^| for |, and ^& for & are not a requirement of sed. sed 's/regex/replace/' or in sed 's#regex#replace#, you would have to escape / or # characters, respectively. sed 's/Parametersettings:/HERE/g' outpad1 > outpad2 I would like the escaped replacement to go where HERE is written in the above. Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Share. The \\ (double backslash) characters are necessary in order to force the shell to pass a \$ (single backslash, dollar sign) to the grep command. sql. Currently kubectl does not accept multiple scopes, so you need to edit the kubeconfig as following: Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand; OverflowAI GenAI features for Teams; OverflowAPI Train & fine-tune LLMs; Labs The future of collective knowledge sharing; About the company Visit the blog By default, sed uses the " POSIX basic regular expressions syntax", so the question mark must be escaped as \? to apply its special meaning, otherwise it matches a literal question mark. Edit: you also need to escape & in the replacement, Sign up using Email and Password Submit. Commented Apr 1, 2016 at 18:09. (This is an extension. Until this chapter, we have only encountered escapes of the form ‘\^’, which tell sed not to interpret the circumflex as a special character, but rather to take it literally. Your problem is not related to escape character, it is caused your sed expression has an additional / sed 's/Date: ///g' Should be writen like sed 's/foo/bar/g' In your case sed 's/Date: //g' Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline (except single quotes), you can't even escape characters there. Whatever comes after the equal sign will be replaced anyway. Put a backslash before $. txt > replace-text. But when the string contains the & character, the sed command is not replacing single quotes that come after that. I created a sed script that cleans up the file (there's lots of "dirty" formatting like double spaces and spaces before/after commas). txt and the scrub. txt Few issues that are fixed: ' instead of " prevents bash interpreting ! symbol and allows referring to backslash as \\; [[:space:]] matches more than just space; you may want it or not, I used the regular space; cat is superfluous here; sed can take file name as an argument (and even if it couldn't, the syntax sed < file. He'd need to upgrade the script to deal with unset variables, too (${URL:?} as a basic minimum). You can test it out: echo "Here is a one is a String" | sed -e 's/one is\(. Warning: This does not consider newlines. I have tried a number of ways of escaping these $ signs but cannot seem to find one that works. answered Aug 8, 2017 at 8:21. sed See is-it-possible-to-escape-regex-metacharacters-reliably-with-sed for which chars can/must be escaped and how each has to be handled. Trying to remove 56 million '' / '' symbol from txt file-1. This matches a string ending with a single backslash. It is a metacharacter that means "the entire pattern that was matched". 5. In sed, s/pattern/replacement/ say "substitute 'replacement' for 'pattern' on What is the proper way of escaping the "=" character in order to add a url with a query string into a form that uses xslt? edit: the equals sign alone breaks it. sed literal-srch-strings. The "t" problem is easy to solve within a loop by using another FOR variable. The regexp contains two backslashes for escaping. @user1190650 That would work if you want to see the "Here is a" as well. sh ABC'\&'12345 But the problem is I should not adjust the input parameter to pass an escape character because the password won't be manually typed. 3. How can I make sed use double quotes (") Also note you can avoid escaping every / by using another separator in sed (I used ~, although it could also be | or another one). */[\]^ and only those characters (but not inside bracket expressions). For example: single_quoted 'This is a string with a '\'single quote\'' Can I Use Escape Sequences In YAML Multiline Strings? Yes, escape sequences can be used in YAML multiline strings. If your text is exposed to neither the command-line nor a command parameter in a . */\1/'. See additional link. Here's an example that touches on escaping in sed but also captures some other quoting issues in bash: It seems that the full answer to this question is found nowhere on the internet, so I finally sat down and figured it out for the Windows case. sed "s/ \& / & /" but once sed gets done with the file, my output looks like. A sed command should usually be inside single quotes because RE metacharacters have too many overlaps with shell metacharacters to be safe. Specifically, the "Windows case" refers to file names that are valid in Windows, meaning that they do not contain the characters \, /, *, ?, ", ^, <, >, |, or line breaks. 005u" w=w1pg+0. 9 using sed. *\)String/\1/'. \. e. However, if you just use \n, you'll just have a line break in your sed pattern, so you have to There are two levels of interpretation, which makes this hard to understand for newbies. The exception is when embedding As tripleee says, here to escape $ both bash and sed participate. , you will have to change the regex to [0-9][0-9. – Ed Morton Commented Sep 17, 2020 at 22:40 Item Description (1) a\Text Places the Text variable in output before reading the next input line. Improve this with a sed command like. For a more in-depth answer, see this SO-question instead. in to replace = on the same file, without creating a new one. This also prevents Compose from interpolating a value, so a $$ allows you to refer to environment variables that you don’t want processed by Compose. Unfortunately, several implementations of sed evidently have a bug that causes them to try to parse balanced brackets in sed. Text files cannot contain NUL characters (at lest partially because many text processing tools are written in C where NUL is the string termination character and so a string variable can't hold a NUL in the middle of it). Uses: File or folder path separation. – Eric Alexander. For bash info bash 3. sed. And, of course, I use every conceivable combination of escape characters under the sun. You have to catch it at the end of a line without the trailing / and you also have to catch it everywhere it has the trailing / (end of line or not). Details of sedscripts and individual sedcommands are discussed in the next chapter. Otherwise you can even use. But no matter what I do, sed will not recognize a literal hyphen. 105u m0 vdda rwld net10 vss nch l="l1pg+0. This is not ideal in many circumstances. How to replace all escape sequences with non-escaped equivalent with unix utilities (sed/tr/awk) Ask Question Asked 3 years, 6 months ago. Follow edited Aug 8, 2017 at 9:53. To include a single quote within a single-quoted string, use the escape sequence \'. txt = foo=. cpp' | sed 's/\*//' => . The ^ escape-character is required by the CMD-shell. You need to escape many of these characters from the shell, but then also some of them need to be escaped from sed after that. It should quote all the values. 5 Character Classes and Bracket Expressions. Clearly, I'm doing something wrong with the & symbol present in my password. txt but Also note, that {,},|,? and + should not be escaped/quoted if they are to represent their literal value unless the -E or -r sed command line option is invoked, in which case they should be i. Both of the approaches above are very useful when it comes to multilevel escaping: $ text="6*6*6 equals 216" $ text="$(printf '%q' "${text on the following example file more ambari-agent. Unfortunately you have been caught out by the fact that & has a special meaning in a sed replacement string. But can you please explain why you use @ffghfgh - urg! I can't figure out how to format the code properly in the comment and now I can't edit the original comment. Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand; OverflowAI GenAI features for Teams; OverflowAPI Train & fine-tune LLMs; Labs The future of collective knowledge sharing; About the company Also, you don't need to escape / in your sed command, because you are not using it as the s/// separator. You still need to "escape" ' chars but the rest should be straight forward. If you really want that, GNU sed (like in Ubuntu) has the shorthand class \s for it:. s is a replacement command, matching a regex being everything after the =. xailihf lvcqyrxy xpq cfwfbo fgrshxq csgsmv lhxkegwk qtxup speseyq hyoli redn vjedp svopt jznuwep gshch