1

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.

Micha Wiedenmann
  • 17,330
  • 20
  • 79
  • 123
AymenTM
  • 429
  • 1
  • 4
  • 10
  • @KenWhite I don't see what I'm looking for :/ – AymenTM Oct 23 '18 at 22:30
  • 1
    https://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 Answers1

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
  • 17,330
  • 20
  • 79
  • 123
  • 1
    Correct. 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