Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 561
DragonX Avatar asked Jun 10 '14 06:06

DragonX


People also ask

How do I use grep to search for multiple patterns?

The basic grep syntax when searching multiple patterns in a file includes using the grep command followed by strings and the name of the file or its path. The patterns need to be enclosed using single quotes and separated by the pipe symbol. Use the backslash before pipe | for regular expressions.

How do I exclude a character in grep?

Excluding words To exclude particular words or lines, use the –invert-match option. Use grep -v as a shorter alternative.

What is difference between grep and Egrep?

The difference between grep and egrep is that the grep is a command that allows searching content according to the given regular expression and displaying the matching lines while egrep is a variant of grep that allows to search content by applying extended regular expressions to display the machining lines.

Which of the following grep commands can be used to exclude the lines that has no character in file txt?

The grep command with “-v” can be used in several ways to exclude the matches from the files. Let's have a sharp look at each one of them one by one.


1 Answers

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?

like image 100
Nancy Avatar answered Sep 20 '22 17:09

Nancy