Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

grep multiple

Use | to separate multiple patterns for the OR condition.

Example: grep 'pattern1|pattern2' filename

Use the -E option to send multiple patterns for the OR condition.

Example: grep -E 'pattern1|pattern2' filename

Using a single -e matches only one pattern, but using multiple -e option matches more than one pattern.

Example: grep -e pattern1 -e pattern2 filename

grep -v can simulate the NOT operation.

There is no AND operator in grep, but you can brute-force simulate AND by using the -E option.

Example : grep -E 'pattern1.*pattern2|pattern2.*pattern1' filename

The above example will match all the lines that contain both pattern1 and pattern2 in either order.)
Source by unix.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #grep #multiple
ADD COMMENT
Topic
Name
7+3 =