I'd like to delete all lines with 3 plus signs:
+++ 3 plus signs
+ 1 plus sign
+++ 3 plus signs
Here's my sed command, escaping the plus signs after beginning of line
sed '/^\+\+\+/d' -> This erase all lines
sed '/^+++/d' -> This works and show only the 1 plus sign line
Why? Is there any problem while escaping the plus sign?
Sed needs many characters to be escaped to get their special meaning. For example, if you escape a digit in the replacement string, it will turn in to a backreference. Remember, if you use a character other than / as delimiter, you need replace the slash in the expressions above wih the character you are using.
Special characters, preceded by \ 's will be taken literally. (Like you've done with your parentheses: ( \( \) )). It should look like this: \' .
"A quick comment. The original sed did not support the "+" metacharacter. GNU sed does if you use the "-r" command line option, which enables extended regular expressions."
(Source)
If you don't use sed -r
, then you don't have to escape +
since it is not considered a metacharacter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With