Either of the these will do:
grep -v "def" input_file | grep "abc"
or
grep "abc" input_file | grep -v "def"
The following will also preserve coloring if you only want to see the output on stdout:
grep --color=always "abc" input_file | grep -v "def"
The -v
option (stands for “invert match”) tells grep
to ignore the lines with the specified pattern – in this case def
.