How to search multiple strings using grep ?

Solution –

grep -E  ‘string1|string2|string3’ filename.txt

                                  or

grep  ‘string1\|string2\|string3’ filename.txt

Below are the content of filename.txt – 

            Linux

            Centos

            Fedora

            Redhat

Suppose we have to check if the file contains Centos and Redhat. For that we can run below commands – 

grep -E 'Centos|Redhat' filename.txt

                              Or

grep 'Centos|Redhat' filename.txt

Leave a Comment

Your email address will not be published. Required fields are marked *