I need to return all files in a directory which contain the string console.log uncommented. So I think I should search for any line which does not have the string // between the newline and the console.log string.
This command returns both commented and uncommented console.log. I want to exclude instances where console.log is commented.
grep -H -r "^.*[^//].*console\.log" /var/www/vhosts/mysite.com
The command I need would match these lines:
var num = 0; console.log(num);
alert('some text'); console.log('anything');
console.log();
but not match these lines:
var num = 0; // console.log(num);
//alert('some text'); console.log('anything');
// console.log();
Use -L switch
grep -rL '//.*console\.log' directory
grep -rlP '^(?!.*//.*console\.log)(?=.*console\.log)' directory
Extending Ωmega's answer: In order to find mulitline comments (/* console.log(); */) additionally use:
^(?!.*//.*console\.log)^(?!.*/\*.*console\.log)(?=.*console\.log)
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