how can I find all lines containing two words?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I need to check if two words are exist on any line in a text file. there are no limits for the characters of the words For example:



I want to find lines of a text that contain the two words cat and elephant together:



Cat is smaller than elephant
Elephant is larger than ca
Cats are cute!
Elephants are very strong
Cat and elephants live in different environment
cats are friendly


In the previous examples, how can I find the lines containing both words



Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment


I tried grep and awk with no hope, the problem is there are words have upper and lower case so how can I match for both words regardless of its letter status!?



thanks for any help









share







New contributor




gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Try with grep again, but use grep -i. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
    – Kusalananda
    8 secs ago














up vote
0
down vote

favorite












I need to check if two words are exist on any line in a text file. there are no limits for the characters of the words For example:



I want to find lines of a text that contain the two words cat and elephant together:



Cat is smaller than elephant
Elephant is larger than ca
Cats are cute!
Elephants are very strong
Cat and elephants live in different environment
cats are friendly


In the previous examples, how can I find the lines containing both words



Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment


I tried grep and awk with no hope, the problem is there are words have upper and lower case so how can I match for both words regardless of its letter status!?



thanks for any help









share







New contributor




gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Try with grep again, but use grep -i. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
    – Kusalananda
    8 secs ago












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I need to check if two words are exist on any line in a text file. there are no limits for the characters of the words For example:



I want to find lines of a text that contain the two words cat and elephant together:



Cat is smaller than elephant
Elephant is larger than ca
Cats are cute!
Elephants are very strong
Cat and elephants live in different environment
cats are friendly


In the previous examples, how can I find the lines containing both words



Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment


I tried grep and awk with no hope, the problem is there are words have upper and lower case so how can I match for both words regardless of its letter status!?



thanks for any help









share







New contributor




gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I need to check if two words are exist on any line in a text file. there are no limits for the characters of the words For example:



I want to find lines of a text that contain the two words cat and elephant together:



Cat is smaller than elephant
Elephant is larger than ca
Cats are cute!
Elephants are very strong
Cat and elephants live in different environment
cats are friendly


In the previous examples, how can I find the lines containing both words



Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment


I tried grep and awk with no hope, the problem is there are words have upper and lower case so how can I match for both words regardless of its letter status!?



thanks for any help







bash





share







New contributor




gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share







New contributor




gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share



share






New contributor




gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 8 mins ago









gormet

1




1




New contributor




gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






gormet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Try with grep again, but use grep -i. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
    – Kusalananda
    8 secs ago
















  • Try with grep again, but use grep -i. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
    – Kusalananda
    8 secs ago















Try with grep again, but use grep -i. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
– Kusalananda
8 secs ago




Try with grep again, but use grep -i. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
– Kusalananda
8 secs ago










1 Answer
1






active

oldest

votes

















up vote
0
down vote













grep -i "cat" file | grep -i "elephant"

Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment


The flag in grep is to ignore case (upper/lower)



 -i, --ignore-case ignore case distinctions




share




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    gormet is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475908%2fhow-can-i-find-all-lines-containing-two-words%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    grep -i "cat" file | grep -i "elephant"

    Cat is smaller than elephant
    Elephant is larger than cat
    Cat and elephants live in different environment


    The flag in grep is to ignore case (upper/lower)



     -i, --ignore-case ignore case distinctions




    share
























      up vote
      0
      down vote













      grep -i "cat" file | grep -i "elephant"

      Cat is smaller than elephant
      Elephant is larger than cat
      Cat and elephants live in different environment


      The flag in grep is to ignore case (upper/lower)



       -i, --ignore-case ignore case distinctions




      share






















        up vote
        0
        down vote










        up vote
        0
        down vote









        grep -i "cat" file | grep -i "elephant"

        Cat is smaller than elephant
        Elephant is larger than cat
        Cat and elephants live in different environment


        The flag in grep is to ignore case (upper/lower)



         -i, --ignore-case ignore case distinctions




        share












        grep -i "cat" file | grep -i "elephant"

        Cat is smaller than elephant
        Elephant is larger than cat
        Cat and elephants live in different environment


        The flag in grep is to ignore case (upper/lower)



         -i, --ignore-case ignore case distinctions





        share











        share


        share










        answered 44 secs ago









        Goro

        9,62364689




        9,62364689




















            gormet is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            gormet is a new contributor. Be nice, and check out our Code of Conduct.












            gormet is a new contributor. Be nice, and check out our Code of Conduct.











            gormet is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475908%2fhow-can-i-find-all-lines-containing-two-words%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay