DragonX
DragonX

Reputation: 391

how to exclude multiple pattern using grep

I want to exclude both "*log*" and ./tags from grep.

What i do is:

grep -rI "PatternToSearch" ./path --exclude="*log*" 

or this:

grep -rI "PatternToSearch" ./path --exclude="tags"

is it possible to merge both exclude patterns in one grep?

Upvotes: 13

Views: 18346

Answers (2)

anubhava
anubhava

Reputation: 786001

Have another --exclude <pattern>:

grep -rI "PatternToSearch" --exclude="*log*" --exclude="tags" .

Upvotes: 4

Nancy
Nancy

Reputation: 1293

Try below:

 grep -rI "PatternToSearch" ./path --exclude={*log*,tags}

Just use "," to separate patterns.

Seems duplicated with how do I use the grep --include option for multiple file types?

Upvotes: 13

Related Questions