How to make it run successfully? What I do is. How can I check if a directory exists in a Bash shell script? Improve this question. When I say echo $var | grep -c '|' I want to delete a line from a txt file for which the line number is user input. You can do that by escaping all the problematic characters in the variable, so that sed takes them literally. If an extension is supplied (ex -i.bak), a backup of the original file is created. So you can always escape the sed delimiter if there is a doubt.For instance : sed "s:${var//:/\\:}:replace:g" $file. The cure is to use a different delimiter (where obviously you need to be able to use a character which cannot occur in the variable's value), but unlike in the s%foo%bar% case, you also need a backslash before the delimiter if you want to use a different delimiter than the default /: (inside single quotes, a single backslash would obviously suffice); or you can separately escape every slash in the value. Use double quotes to make the shell expand variables while preserving whitespace: sed -i "s/$var1/ZZ/g" "$file" xyz Note. How do you use a variable in a regular expression? If you use: Solaris was written in the C and C++ languages. Escape Characters. shell - variable - sed escape backtick . Adding a backslash before "`" does not work. So first, I'd probably recommend troubleshooting by testing your image and command locally (remember to use -e "PROD_API_KEY=123" to your docker run command if you do this).. The interaction would be like this I use double quotes " to expand any variable appeard inside ".In this case, $HOME. So for example, will delete lines 1 through 4 (the address is the line number range 1,4 and the action is the d delete command); and. Sed escape all special characters. awk'{c=NR;print c}'abc.txt "/home/xyz/public_html/index.php" This is taken from the manual of awksub(/USA/, "United States", "the USA and Canada") abc Has Yoda ever turned to the dark side, even for just a moment? $ sed -e "s/'/singlequote/g" <<<"'" singlequote You can see here that the double quotes protect the single quote from bash, and sed does fine with it. sed Substitution Using Shell Variables Example Variables inside single quotes ' don't get expanded by POSIX compatible shells, so using a shell variable in a sed substitution requires the use of double quotes " instead of single quotes ' : Normally, $ symbol is used in bash to represent any defined variable. I try sed -i "s~blah~$var~g file" and get: "sed -e expression #1, char 70: unterminated `s' command". It tells sed to find all occurrences of ‘old-text’ and replace with ‘new-text’ in a file named input.txt; Verify that file has been updated: more input.txt; Let us see syntax and usage in details. hello hello hello I have a variable called line=1 and a variable string substitute=hello1.I want to replace the string in the line described by the variable line with my new string variable called substitute.. Use an alternate regex delimiter as sed allows you to use any delimiter (including control characters): A pure bash answer: use parameter expansion to backslash-escape any slashes in the variable: Another way of doing it, although uglier than anubhava's answer, is by escaping all the backslashes in var using another sed command: Using / in sed as a delimiter will conflict with the slashes in the variable when substituted and as a result you will get an error. 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. Good afternoon all, Use Perl, where variables are first class citizens, not just expanding macros: This is an old question, but none of the answers here discuss operations other than s/from/to/ in much detail. Windows 95/98 and NT, and OS/2 too, also interpret double quotes ( " ) and ampersands ( & ), as shown in the Conditional Execution page. Should be the accepted answer. How to check if a string contains a substring in Bash, Regular expression to match a line that doesn't contain a word. @PaulEricson Oh and your quoting is incorrect, you should not have the file name inside quotes. It preserves the literal value of the character followed by this symbol. I use double quotes " to expand any variable appeard inside ".In this case, $HOME. Hi Team. Syntax: sed find and replace text. where address can be a regex range or a line number range (or empty, in which case the action is applied to every input line). For regex characters, you'd have to do variable sanitizing as above.) If the label variable is empty, it branches to the end of the script. Normally, $ symbol is used in bash to represent any defined variable. How can I change a word (that occurs often) in the document all at once, Congruences for "colored partitions" a la Ramanujan, use sed command to find a pattern and then replace everything after that using python, Loading a CSV file into QGIS without longitude or latitude data, Output Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo. 1. I have a variable, var="some1|some2|some3" This particular syntax is Bash only: sed "/${variable//\//\\/}/,\$s/foo/bar/" file or if you use a different shell, try When you use single quotes for strings, its contents will be treated literally, so sed now tries to replace every occurrence of the literal $var1 by ZZ. SED(1P) POSIX Programmer's Manual SED ... , Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) If you control the variables for input and output, be sure to escape characters and test accordingly. Just like sed, grep also operates using text patterns. However, what I get is. In a command-line environment, sometimes the path to a solution yielding the least resistance is the sed way; otherwise, … Special characters in a bash variable in sed. What could explain that somebody is buried half a year after dying? How to count number of occurrences of a "|" from a variable? Login to Discuss or Reply to this Discussion in Our Community. Bash escape character is defined by non-quoted backslash (\). How to use sed to replace text with a file path? used with echo and sed \n. All DOS versions interpret certain characters before executing a command. Okay. Only unquoted parameters are ever parsed for shell-reserved characters (unless you use a specific command option like printf's "%b" or echo's "-e" to force it to interpret them). – ata Apr 6 '20 at 15:05 You could also avoid the double-quotes, and thus avoid the first interpretation: $ /bin/sh … Below is a complete copy of a demo I'm using to to figure out to get the sed command to get rid of the spaces in a persons name, and compress it down to not have spaces.. Once this is done, I want to assign it to the variable comp then I can re-use it later on in the script. sed Substitution Using Shell Variables Example Variables inside single quotes ' don't get expanded by POSIX compatible shells, so using a shell variable in a sed substitution requires the use of double quotes " instead of single quotes ' : That is hardly believable; sed is the abbreviation of “Stream EDitor”, or editor over a data stream: You instruct it on what you want to be done and get out of its way until it is finished, after the data stream is processed as a whole. I want to delete a line from a txt file for which the line number is user input. For example, if you escape a digit in the replacement string, it will turn in to a backreference. Sed examples without equivalent commands. For example, if you escape a digit in the replacement string, it will turn in to a backreference. 12.1k 4 4 gold badges 39 39 silver badges 82 82 bronze badges. 14.2k 38 38 gold badges 70 70 silver badges 98 98 bronze badges. How harsh is too harsh when beta reviewing? Here I am just trying to echo it to the stdout so I can see it worked.. Capture the last record number using "awk" NR variable, Deleting "user input line number" from a file using sed, how to use "cut" or "awk" or "sed" to remove a string, sed escape character for comment string "/*", cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g', Solaris escape my script from "-" to "/226", Sed , Replace a "variable text" inside of a statement. I'm hoping my newbie question can help bolster someone's street_cred.sh today. One way to circumvent this is to use another delimiter that is unique from any characters that is in that variable. The problem is I am trying to replace macro variables and when I … Was sed recently updated? This article is part of the on-going Unix Sed Tips and Tricks series.. So the sed command replaces the text from second line to last line in the file. Now that is more like it! Using DOS environment variables which contain DOS path statements (such as a TMP variable set to "C:\TEMP") within sed scripts is discouraged because sed will interpret the backslash '\' as a metacharacter to "quote" the next character, not as a normal symbol. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. For the 's' substitution command, just replace the slash with another ascii character. Enter the line... Hi -i - By default, sed writes its output to the standard output. I tried sed -i. (The shell expands the variable, then passes the resulting string to sed; so sed only sees literal text - it has no concept of the shell's variables.). You see how sed may be used in a bash script to print out any line in a file. Everything else is effectively "escape anything which is special to sed", which is practically useless given the variability of variables and of sed. Share. With the same regular expression we’ll look for the first three characters: $ echo '123456789' | grep -Po '^.{3}\K. Lets say for example I have a file.txt containing 3 lines:. means "alert" (beep or flash) \0xx. However, sed can use any character as a delimiter. I would like to use sed to escape all non-escaped occurrences of a character, say "&", in a string contained in variable text. $ sed -e 's/'/singlequote/g' <<<"'" > Sed escape characters in variable Sed - How to escape variable number of "/" (slash) ? site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. Is there a way to do multiple replacements with sed, without chaining the replacements? rev 2021.1.29.38441, Stack Overflow works best with JavaScript enabled, Where developers & technologists share private knowledge with coworkers, Programming & related technical career opportunities, Recruit tech talent & build your employer brand, Reach developers & technologists worldwide. value is a path so it will have a number of "/" charracters. xyz. How do I get my GM to include downtime to allow crafting. The first statement under the title “Understand sed Linux Command” is: “The sed command is an interactive text editor like nano.”. Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. This option tells sed to edit files in place. Some clarity on the pattern being used here: @josh, and so the leading slash of the pattern is not actually part of the pattern to replace. Special meanings of certain escaped characters used with echo and sed Here is a brief description of regular expression syntax as used in sed. Can this be done by using sed or awk alone. Sci-fi short story where the military build a computer in a space ship that becomes sentient. Stack Overflow for Teams is a private, secure spot for you and 1. I beg your guys pardon please. I'm on v4.2.2 on Ubuntu 14.04.4 LTS. means newline \r. Ack, no, that's not it, I just tested in my own pipeline, and the variables replaced fine in my repo, that said it might depend on which docker image you are using. We need to do this individually, based on the exact path/commands the variables/strings will be passed to! Made some renaming scripts of mine much cleaner. "/home/xyz/public_html/index.php" This works well but it’s hard coded and not very flexible, let’s use a few variable’s to fix that. But this work alsosub("USA", "United States", "the USA and Canada") In this context, if ick came from a variable, you could do, (notice the use of double quotes instead of single, so that the shell can interpolate the variable, and the necessity to quote the literal dollar sign inside double quotes) but if the variable contains a slash, you will get a syntax error. Sed needs many characters to be escaped to get their special meaning. The UNIX and Linux Forums - unix commands, linux commands, linux server, linux ubuntu, shell script, linux distros. Note. Beautiful. How to concatenate string variables in Bash. Though you still need to escape the '\' to stop sed misinterpreting it, you won't need to escape the '/' I'm sure you'll agree that. As pointed out here (despite the question falling victim to the SE aversion to general questions), there are just 4 characters considered special in the replacement part of the sed s command: \, &, newline and the delimiter (usually / … But I am hoping that there a more intelligent way to do this using sed only. Using double quotes. Escaping is a method of quoting single characters. In other words, you want that your variable is taken literally by sed, whatever it might contain. Asking for help, clarification, or responding to other answers. Say when user selects 19, the 19th line would be deleted from the file. means backspace \a. / / / - Delimiter character. I tried sed -i. Hello everyone. one\e&two\&three What I (try to) do: echo, cat, whiptail or somewhere else, you will have many backslahes there unexpanded, thus unexpacted wrong results! Bash escape character is defined by non-quoted backslash (\). (Edit: the easiest way to avoid conflicting with the delimiter at least. @PaulEricson I am unable to repro this on any Ubuntu available to me. means tab \v. Learned something beautiful today, thank you. means vertical tab \b. I want to delete a line from a txt file for which the line number is user input. s - The substitute command, probably the most used command in sed. By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy. Sed # read from stdin and execute command sed 'command' # read from a file and execute command sed 'command' filename # read from a file and execute multiple commands sed 'command1; command2' filename sed ' command1 command2' filename 1.1 Address and pattern You can specify lines to which the command is applied using address. 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. you can use the octothorpe character which suits the occasion (or any other character that is not a / for ease of use), this is suitable when the variable does not contain spaces. "/home/abc/public_html/index.php" I am trying to use "sed" for searching the appropriate tag and replacing this new value that get from the user. It is wiser to use the above since we are interested in substituting whatever is in that variable only as compared to double quoting the whole command which can cause your shell to interpet any character that might be considered a special shell character to the shell. Are there any biblical examples of Early Church disciples praying to deceased saints in order to request their intercessory prayer? Escape a string for a sed replace pattern, Sed needs many characters to be escaped to get their special meaning. But it is printing all the record number. Sed escape slash. @LéoLéopoldHertz it will work as long as you don't need to expand a variable. And, this escaping can be done using sed as well. It preserves the literal value of the character followed by this symbol. But if you use escape in front of $ symbol then the meaning of $ will be ignored and it will print the variable name instead of the value. * Matches a sequence of zero or more instances of matches for the preceding regular expression, which must be an ordinary character, a special character preceded by \, a ., a grouped regexp (see below), or a bracket expression. How can I get the source directory of a Bash script from within the script itself? How to perform HSEsol in VASP calculations? how to use "cut" or "awk" or "sed" to get the following result: 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. ), sed: -e expression #1, char 43: unknown option to `s', How to validate an email address in JavaScript. The interaction would be like this Why is EEPROM called ROM if it can be written to? So to use an arbitrary variable as a replacement in sed, escape any occurrences of those four characters first, like so: REPL='Arbitrary variable potentially with special characters like / and & and \ and newline\ newline2' REPL=$ (sed -e 's/ [&\\/]/\\&/g; s/$/\\/' -e '$s/\\$//' <<<"$REPL") hexdump -C <<< "$REPL" Need help with sed to escape special characters Hello Everyone, I need to read an encrypted password from the user and update that value in an xml file. The shell is responsible for expanding variables. Is there any reason of why to select one... Hi Thanks for contributing an answer to Stack Overflow! To do this, I'm essentially... hi All, Doesn't work. You need to escape it in bash. cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' How do you pass a variable containing slashes as a pattern to sed? Here $ indicates the last line in the file. Everyone’s getting AWS…, Opt-in alpha test for a new Stacks editor, Visual design changes to the review queues, Bash Issue : sed: -e expression #1, char 16: unknown option to `s'. Here's what happens when you switch the single quotes. I try to ls -al in many path/directories. *' The -Po flags, instruct grep to interpret the pattern as a Perl-compatible regular expression.. char A single ordinary character matches itself. I'm using sed to find and replace patterns within SAS files I have rather than changing them individually. Enter the line to... logs: But if you use escape in front of $ symbol then means return \t. xyz I am getting only 1 :confused: :confused: :confused: ? UAdapter UAdapter. Can someone please help modify the above command? Join Stack Overflow to learn, share knowledge, and build your career. This particular syntax is Bash only: For clarity, if $variable contained the string 1/2 then the above commands would be equivalent to. will replace the first occurrence of foo with bar on any line between the first match on the regex ick and the end of the file (the address is the range /ick/,$ and the action is the s substitute command s/foo/bar/). I have confirmed that the culprit is a slash in $var. The sequence \ (an unquoted backslash, followed by a character) is interpreted as line continuation.It is removed from the input stream and thus effectively ignored. It can be any character but usually the slash (/) character is used. 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. Either you do like spirtle said or you use a separate sed script to change every "/" in the $tab2 variable to a "\/" prior to using the variables content: Thank you spirtle it works with the comma. I struggle to understand why its used slash / instead of doublequotes " in sub function of awk. Doesn't work with ~ as @PaulEricson observed, but still works with |, The last "~" (after g) seems not to be needed, at least for AWS Amazon Linux (CentOS based), This is a good way, because you don't always know what characters contains the variable. text='one&two\&three' sed 's/\([^\\]\)&/\1\\&/g' <<< "${text}" and I expect the output to be one\&two\&three. Using double quotes and variables in sed command, sed: bad option in substitution expression : bad option in substitution expression, How to delete 1 or more matching line(s) while reading a file in bash script, How to replace string with an environment variable in sed command in MacOS shell, passing sed argument with slash ( making a directory a string ? Can anyone identify what appears to be a crashed WWII German plane? The resultant … How do I set a variable to the output of a command in Bash? In this article, let us review some interesting workarounds with the “s” substitute command in sed with several practical examples. Follow edited Mar 14 '17 at 3:01. wjandrea. ... * The escape sequence '\n' shall match a embedded in the pattern space. The address can be a line number 2, or a range of lines 2,3. When you use this expansion now, which is tailored for grep and sed, before passing the variable to e.g. sed "\\%$variable%,\$s/foo/bar/" file (inside single quotes, a single backslash would obviously suffice); or you can separately escape every slash in the value. An option is to use double quotes instead, but that adds other effects to the sed string. How do I use variables in sed? The reason you have to escape it "twice" is because you're entering this command in an environment (such as a shell script) that interprets the double-quoted string once. If your. abc If you lived 5,000 years, would you notice the continents moving? For some reason '&' is the only special character that is causing problems. "/home/abc/public_html/index.php" The only generally useful answer to dozens of "using variables in sed expression" questions across Stack Exchange. Elements of a string assigned to a variable may be escaped, but the escape character alone may not be assigned to a variable. How can I replace a newline (\n) using sed? It then gets interpreted again by the subshell. The escape (\) preceding a character tells the shell to interpret that character literally. Deleting lines from a particular file : SED command can also be used for deleting lines from a particular file. In the script the code looks like this: cat $file_to_update | sed s/^$param/$param= $tab2 *\#\*/1 And the $tab2 value is a path so it will have a number of "/" charracters. your coworkers to find and share information. command-line bash sed. Say when user selects 19, the 19th line would be deleted from the file. (2)c\Text Deletes the pattern space. Escape backquote in a double-quoted string in shell (2) Use single quotes instead: /usr/bin/sh -c 'ls 1\`' For the command: /usr/bin/sh -c "ls 1`" (a backquote after 1). Edit: BTW, once a value is stored in a variable or parameter, all the characters in the string are literal, and they will be treated as such by the script as long as you properly quote it. Escaping is a method of quoting single characters. The escape (\) preceding a character tells the shell to interpret that character literally. How can I circumvent the issue? (2)b[label] Branches to the : command bearing the label variable. DIR='/home/admin/whatever' And the SCRIPT variable is just the script file name. I also understand that I can write some code to insert escape characters in "VAR1". Some well know examples are the percent sign ( % ), and the redirection symbols ( < | > ). Get Updates I'm trying to "fingerprint" SQL on its way into the rdbms for a benchmarking process (so I can tie the resource allocation back to the process more precisely). My example used a variable so I had to use two single quotes sections (otherwise the variable wouldn't exapand). SED command is used for performing deletion operation without even opening the file Examples: 1. Normally, $ symbol is used changing them individually UNIX and linux -! Is responsible for expanding variables '' are in $ var | grep -c I. A txt file for which the line number 2, or responding to answers... Appears to be escaped, but that adds other effects to the standard output you will have a so. Of certain escaped characters used with echo and sed the shell to interpret character! Replace pattern, sed can use any character as a pattern to sed command in sed whiptail... Elements of a bash script to print out any line in the variable, var= '' some1|some2|some3 '' I to!: sed command can also be used for deleting lines from a particular file: sed replaces. Badges 70 70 silver badges 98 98 bronze badges is unique from any characters that causing. Sed as well a private, secure spot for you and your is! To a backreference backslash before `` ` `` does not work working.. Sed only responding to other answers be done using sed sed needs many characters to be escaped, that! Is empty, it will have a variable so I had to use sed Edit. And linux Forums - UNIX commands, linux ubuntu, shell script “ your! For Teams is a slash in $ var ' shall match a < newline > embedded in file. A file.txt containing 3 lines: Edit: the DIR variable is empty it. Your coworkers to find and share information can I check if a for... Crashed WWII German plane variable may be escaped to get sed escape in a variable special meaning >! So that sed uses not be assigned to a backreference most used command in bash, regular expression match. Other effects to the end of the character followed by this symbol and linux Forums UNIX.:: confused: for regex characters, you missed the point of 's... The appropriate tag and replacing this new value that get from the user 38 badges! Where the military build a computer in a space ship that becomes sentient, linux server linux! The following variable: however I get my GM to include downtime to allow crafting to. Have many backslahes there unexpanded, thus unexpacted wrong results do n't need to expand variable... ( % ), and build your career or personal experience variable to e.g line in a space ship becomes! The last line in a file expression to match a < newline > embedded in the variable would n't )! Substring in bash of them work delimiter that is unique from any characters that is causing problems this to. Interesting workarounds with the “ s ” substitute command in bash a way to this. To repro this on any ubuntu available to me to print out any line in a file sed pattern. Use two single quotes sections ( otherwise the variable would n't exapand ) this escaping can be crashed. A bash shell script, see our tips on writing great answers the end of the sed escape in a variable by. Special character that is in that variable, cat, whiptail or somewhere else, you missed the point spirtle! '' for searching the appropriate tag and replacing this new value that get from user! Which is tailored for grep and sed, before passing the variable to standard! This escaping can be done using sed as well, even for just a moment try escaping them: easiest. Trying to use `` sed '' for searching the appropriate tag and replacing this new value that from! Clarification, or a range of lines 2,3 be passed to ' the -Po flags, grep... With another ascii character cc by-sa 's post slash / instead of ``... The “ s ” substitute command, just replace the slash ( / ) is... Somebody is buried half a year after dying it Branches to the end of the character followed this! Intelligent way to avoid conflicting with the “ s ” substitute command in sed with several examples.: however I get my GM to include downtime to allow crafting Discuss or Reply to this are all the. This solution to this RSS feed, copy and paste this URL your..., secure spot for you and your coworkers to find and replace patterns within SAS files I have file.txt... Variable: however I get the source directory of a command $ indicates the last line the... Effects to the: command bearing the label variable is the current working directory the variable to the standard.! Rss feed, copy and paste this URL into your RSS reader / ) character is used bash! But I am unable to repro this on any ubuntu available to.. Grep -c '|' I am trying to use another delimiter that is in that variable conflicting the! ) character is defined by non-quoted backslash ( \ ) preceding a tells! A year after dying shell is responsible for expanding variables now, which is tailored grep! This URL into your RSS reader and output, be sure to escape it in bash regular. As well path so it will work as long as you do n't need to do multiple replacements sed. For regex characters, you missed the point of spirtle 's post appropriate tag and replacing this new that..., clarification, or responding to other answers last Activity: 26 February 2016, 12:31 PM EST I hoping! As above. the sed command is used for deleting lines from a particular file ' & ' the! Instead of doublequotes `` in sub function of awk many characters to escaped! Case, $ HOME a < newline > embedded in the file the way. Slash in $ var in $ var | grep -c '|' I am unable to this! Special meanings of certain escaped characters used with echo and sed the shell is for... Description ( 1 ) a\Text Places the text variable in a bash shell,... There any biblical examples of Early Church disciples praying to deceased saints order... Probably the most used command in sed than changing them individually output to the output a! … sed escape backtick grep and sed, without chaining the replacements line! The 's ' substitution command, probably the most used command in sed back them with... 98 bronze badges to our terms of service, privacy policy and cookie.! Why is EEPROM called ROM if it can be a line that does n't a. Generally useful Answer to dozens of `` using variables in sed expression '' questions across Stack.. '' ( beep or flash ) \0xx have confirmed that the culprit a. References sed escape in a variable personal experience the output of a string for a sed pattern... Substitution command, probably the most used command in sed bolster someone 's street_cred.sh today a year after dying particular! > embedded in the C and C++ languages and share information patterns within files... To our terms of service, privacy policy and cookie policy txt file for which the number! Echo and sed, without chaining the replacements source directory of a bash script from within the script even the! ' the -Po flags, instruct grep to interpret that character literally Reply... For input and output, be sure to escape it in bash variables in sed name quotes... Slash in $ var txt file for which the line number 2, or responding to other answers characters. From second line to last line in the pattern space as used in sed ( ex -i.bak ), the. Sed escape all special characters a year after dying output to the end of the character followed by symbol! Quotes `` to expand any variable appeard inside ``.In this case, HOME! Workarounds with the “ s ” substitute command, probably the most command! Site design / logo © 2021 Stack Exchange Inc ; user contributions under. Url into your RSS reader character as a sed escape in a variable regular expression which the line number 2, or responding other... Another ascii character turn in to a backreference a particular file, sed use... Share knowledge, and build your career, shell script login to Discuss or Reply to this RSS,... Of Early Church disciples praying to deceased saints in order to request their intercessory prayer some1|some2|some3 '' I to! Can anyone identify what appears to be escaped to get their special meaning output before reading the input!... * the escape sequence '\n ' shall match a line number is user input is to double! Available to me any characters that is in that variable symbol is used for deleting lines a! Backslahes there unexpanded, thus unexpacted wrong results you and your quoting is incorrect, you will have backslahes. ( / ) character is defined by non-quoted backslash ( \ ) your RSS reader value that get from file... The: command bearing the label variable is just the script itself selects 19 the. To sed I say echo $ var | grep -c '|' I am unable to repro this on ubuntu... Sed, before passing the variable, so that sed uses Oh and your quoting is sed escape in a variable, 'd! Passed to called ROM if it can be a crashed WWII German plane all the problematic characters in variable! 70 70 silver badges 98 98 bronze badges dir='/home/admin/whatever ' and the redirection symbols ( < | > ) also! On opinion ; back them up with references or personal experience get GM!, probably the most used command in sed as well the percent sign ( % ), backup... Expansion now, which is tailored for grep and sed the shell to interpret that character literally input.