reverse matching

Hello guys

How can I use egrep to match word1 but not word2...word1.

What I mean

suppose that I have the following text, and my word1=pizza and word2=eat

I hate to eat pizza because I ma eating it each day
Pizza is good
I like vegetarian and Italian Pizza
eating healthy food is good, but I can not resist The pizza
what about pizza or do you prefer burger

So I want to get

pizza is good
I like vegetarian and Italian Pizza
what about pizza or do you prefer burger

Thanks in advance

Something like:

grep pizza file | grep -v eat

?

In there is another way to do it without -v for two reasons. The files I am working on is extremely large and I am just interested to see if the pattern exist or not
i.e
Currently I am using
cat $path/tmpFile.csv | egrep "$word1" -i -q
if [ "$?" -eq "0" ]; then
echo "found"
...

I found this link
regex - Regular expression to match string not containing a word? - Stack Overflow

But I could not get it

Try:

grep -i pizza "$path/tmpFile.csv" | grep -iv eat > /dev/null
if [ "$?" -eq "0" ]; then 
echo "found"

thanks for the reply bartus11
I will use your method
Regards

you can use awk with operators

$ awk 'BEGIN{IGNORECASE=1}/pizza/ && !/eat/' file

Or Ruby(1.9+)

$ ruby -ne 'print if /pizza/i && !/eat/' file

But then $? is useless :wink: It is set to "0" even if the string was not found, so you have to code whole solution in AWK.

Same proposal as Bartus post #2 except that the search for word1 will not be case sensitive

grep -i pizza infile | grep -v eat