I've seen this question: Regular expression to match a line that doesn't contain a word?
But I can't get it to work. I have a shell script and I'm using
string1.*string2.*string3
To search for 3 words in a file, in that order. But I want to change it so that if badword5 is anywhere in between those words in that file, there is no regex match with grep.
So this should match:
./testing/test.txt: let prep = "select string1, dog from cat",
" where apple = 1",
" and string2 = 2",
" and grass = 8",
" and string3 = ?"
But this should not:
./testing/test.txt: let prep = "select string1, dog from cat",
" where apple = 1",
" and string2 = 2",
" and grass = 8",
" and badword5 = 4",
" and string3 = ?"
I unsuccessfully tried:
string1((?!badword5)|.)*string2((?!badword5)|.)*string3
The entire script:
find . -name "$file_to_check" 2>/null | while read $FILE
do
tr '\n' ' ' <"$FILE" | if grep -q "string1.*string2.*string3"; then echo "$FILE" ; fi
done >> $grep_out