There are lot of ways to use grep with logical operators.
Use Using multiple
\|-eto separate multipleoptions matches anything that matches any of the patterns for, giving the OR conditionoperation.Example:
grep 'pattern1\|pattern2'-e pattern1 -e pattern2 filenameUse theIn extended regular expressions (
grep -Eoption), you can use|to sendcombine multiple patterns forwith the OR condition operation.Example:
grep -E 'pattern1|pattern2' filenameUsing a single
-ematches only one pattern, but using multiple-eoption matches more than one pattern.Example:
grep -e pattern1 -e pattern2 filenamegrep -vcan simulate the NOT operation.There is no AND operator in
grep, but you can brute-force simulate AND by using themultiple patterns with-E|option.Example :
grep -E 'pattern1.*pattern2|pattern2.*pattern1' filenameThe above example will match all the lines that contain both pattern1 and pattern2 in either order.) This gets very ugly if there are more patterns to combine.