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?
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.
Excluding words To exclude particular words or lines, use the –invert-match option. Use grep -v as a shorter alternative.
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With