Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping plus signs doesn't work

Tags:

regex

sed

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?

like image 380
Tom Avatar asked May 08 '13 12:05

Tom


People also ask

Do I need to escape characters in sed?

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.

How to handle special characters in sed command?

Special characters, preceded by \ 's will be taken literally. (Like you've done with your parentheses: ( \( \) )). It should look like this: \' .


1 Answers

"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.

like image 184
JonasVautherin Avatar answered Oct 20 '22 13:10

JonasVautherin