Issue
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();
Solution
Use -L
switch
grep -rL '//.*console\.log' directory
Update:
grep -rlP '^(?!.*//.*console\.log)(?=.*console\.log)' directory
Answered By - Ωmega