Reputation: 6901
I'm writing a shell script that finds occurences a string ($string) of a certain filetype ($ext) in the current working directory ($cwd).
I also want to exclude all files that contain a certain string ("mbundle").
How would I amend what I have, to do that?
grep -nrwl $string --include=\*."$ext" "$cwd"
Sorry, I'm still pretty new to grep and regex/globbing patterns etc
Upvotes: 1
Views: 782
Reputation: 784898
If your grep
supports -P
(PCRE) option then you can use negative lookahead
to avoid matching mbundle
:
grep -P -nrwl "(?!.*?mbundle)$string" --include=\*."$ext" "$cwd"
Upvotes: 1