I would just pass that through a second grep
to remove them:
grep -r --exclude={\*~,\*.map} "OK" bar/ | grep -vP '(?<!debug)\.js'
The -v
reverses the match, printing lines that don't match the pattern and the -P
enables Perl Compatible Regular Expressions which let us use negative lookbehinds. This particular regex, will match .js
that is not prececeded by debug
which means (since we are inverting the matches) that only those .js
files will be printed.
However, as @QuestionOverflow pointed out int the comments, that could have the unintended side effect of filtering out lines that contain OK
and js
since the grep -v
is applied to the entire output, not only the file name. To avoid that, just add a colon (that's what grep
uses to separate file names from file contents):
grep -r --exclude={*~,*.map} "OK" bar/ | grep -vP '(?<!debug).js:'
That will still fail if your input line contains foo.js:
or if your file name contains :
. So, to be sure, use a different approach:
grep -Tr --exclude={*~,*.map} "OK" bar/ | grep -vP '(?<!debug).js\t'
The -T
causes grep
to print a tab between the file name and the file contents. So, if we simply add a \t
to the end of the regex, it will only match against file names, and not the contents of the line.
Still, using find
might make more sense regardless.