There are lot of ways to use grep with logical operators.
Use
\|to separate multiple patterns for the OR condition.Example:
grep 'pattern1\|pattern2' filenameUse the
-Eoption to send multiple patterns for the OR condition.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 the-Eoption.Example :
grep -E 'pattern1.*pattern2|pattern2.*pattern1' filenameThe above example will match all the lines that contain both pattern1 and pattern2 in either order.)