I came across someone doing: grep -v "\#"
. Could someone just quickly explain what happens when you precede a character that is not an escape character (like '#
') with a backslash.
Asked
Active
Viewed 32 times
1

Micha Wiedenmann
- 19,979
- 21
- 92
- 137

AymenTM
- 529
- 2
- 5
- 17
-
@KenWhite I don't see what I'm looking for :/ – AymenTM Oct 23 '18 at 22:30
-
1https://regex101.com/ is of great help. – Micha Wiedenmann Oct 23 '18 at 22:43
-
I do not think that this is a good duplicate simply because I searched for backslash as used in this question in the linked answer but found no answer there. And while it is possible that the linked answer describes `\` + `literal character` it is not easily discoverable. Additionally the comments under the linked answer share the same sentiment. – Micha Wiedenmann Oct 24 '18 at 06:28
1 Answers
1
\#
is a regular expression which matches the literal character #
. Infact the backslash is not needed since the regular expression #
is simpler and serves the same purpose.

Micha Wiedenmann
- 19,979
- 21
- 92
- 137
-
1Correct. In the context of a regexp, a backslash before anything *other than* a letter or number is treated as forcing that character to be literal, and if that character happens to not be special, it does nothing. – dgatwood Oct 23 '18 at 22:43