Does anybody know what the complete list of special characters in sed
are ?
Please don't give an answer like, it is the same list of special characters for grep
, because that just transforms my question to: Does anybody know what the complete list of special characters in grep
are?
The special character in sed are the same as those in grep, with one key difference: the forward slash / is a special character in sed. The reason for this will become very clear when studying sed commands.
Special characters, preceded by \ 's will be taken literally. (Like you've done with your parentheses: ( \( \) )).
Put a backslash before $. */[\]^ and only those characters (but not inside bracket expressions).
It depends. Strictly speaking, a standard compliant sed must only use Basic Regular Expressions for which the standard states:
The BRE special characters and the contexts in which they have their special meaning are as follows:
.[\
The period, left-square-bracket, and backslash shall be special except when used in a bracket expression (see RE Bracket Expression ). An expression containing a '[' that is not preceded by a backslash and is not part of a bracket expression produces undefined results.
*
The asterisk shall be special except when used in a bracket expression, as the first character of an entire BRE (after an initial '^' , if any), or as the first character of a subexpression (after an initial '^' , if any); see BREs Matching Multiple Characters
^
The circumflex shall be special when used as an anchor (see BRE Expression Anchoring )
or as the first character of a bracket expression (see RE Bracket Expression )
$
The dollar-sign shall be special when used as an anchor.
So the complete list is .[\*^$
, but context matters. Also, many sed provide options to use extended regular expressions(EREs), which will expand the list and change the context in which characters are special. For example, without EREs groupings are formed using \(
and \)
, but with EREs (
and )
by themselves are special and must be escaped to be matched literally.
I think this is the full list of characters [\^$.|?*+() on which sed will respond in a manner different than a normal character.
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