2

The issue may be the fact that I am ignoring multiple strings, but here is what I'm doing at the moment:

grep -Ev 'lost+found|controller|config'

All lines with 'controller' and 'config' are being ignored, but all lines with 'lost+found' are still appearing. Is there a workaround to ignore strings that include the '+' symbol?

Guerrette
  • 67
  • 1
  • 7
  • 2
    Escape the `+`: `\+`. – zwer Jul 13 '17 at 00:46
  • 2
    You need to learn what characters have special meaning in regular expressions, and escape them if you want them to be treated literally. – Barmar Jul 13 '17 at 00:49
  • 3
    `+` is a literal when `grep` uses basic regular expression. But `-E` turns `extended regular expression` on. This gives meaning to `+` which is 1 or more occurrence of the previous expression. – alvits Jul 13 '17 at 01:12
  • Possible duplicate of [What special characters must be escaped in regular expressions?](https://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions) – Wiktor Stribiżew Jul 13 '17 at 06:48

1 Answers1

4

Dealing with lost+found|controller|config:

lost+found matches 1 or more occurrences of t in lostttt.

As @zwer and @Barmar mention, a + indicates repetition.

Effectively, what is matched is:

enter image description here

Changing the + to a \+ (escaping the special character) now matches what you need:

enter image description here

Regex101 is a great resource to explore what your regex does:

enter image description here

Jedi
  • 3,088
  • 2
  • 28
  • 47