Reputation: 307
Below are the sample files in which I am looking for the files that doesnt have the word "DEF" or is commented out if exists.
cat text.txt_1
ABC
DEF
GHI
cat text.txt_2
ABC
#DEF
GHI
cat text.txt_3
ABC
GHI
I am trying to do something like this grep -Lr "DEF" . || grep -iwr "DEF" . | grep "^#"
but it is not working
Thanks in Advance!
Upvotes: 1
Views: 47
Reputation: 785128
If you have gnu grep
then use:
grep -zvlr '^[^#]*DEF'
Otherwise, you can use awk
with find
:
find . -type f -name 'text.*' -exec awk '/^[^#]*DEF/{p=1} END{if (!p) print FILENAME}' {} \;
Upvotes: 1