Guerrette
Guerrette

Reputation: 67

How to ignore a string that includes a '+'

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?

Upvotes: 2

Views: 314

Answers (1)

Jedi
Jedi

Reputation: 3348

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

Upvotes: 4

Related Questions