0

Say I have a project with a bunch of .js files. I want to find out which files do not contain this line:

const process = require('suman-browser-polyfills/modules/process');

If I do

grep -v "suman-browser-polyfills/modules/process" .

then it will simply log every line of every file that does not match. That's not going to give me what I want at all.

Does anyone know a good way to do this?

3
  • 1
    -L, --files-without-match Suppress normal output; instead print the name of each input file from which no output would normally have been printed. – steeldriver Oct 21 '17 at 17:53
  • thanks, -L is alias for --files-without-match? – Alexander Mills Oct 21 '17 at 17:53
  • 1
    @steeldriver You should make this an answer because otherwise is looks like this question had not been answered yet. – Hauke Laging Oct 21 '17 at 17:57
3

You can use the -L option (or its long option equivalent, --files-without-match

From the General Output Control section of man grep:

 -L, --files-without-match
       Suppress normal output; instead print the  name  of  each  input
       file from which no output would normally have been printed.  The
       scanning will stop on the first match.

So for example,

 grep -FL "const process = require('suman-browser-polyfills/modules/process');" *.js

(the -F option tells grep to treat the search pattern as a fixed string, rather than a regular expression - there don't appear to be any regex-special characters in your example pattern, but we shouldn't assume that will always be the case.)

1
  • thanks nice answer, at first I thought I needed the grep -v option, but you demonstrated that I don't want that. – Alexander Mills Oct 21 '17 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.