How to combine two grep statements and display their results together?

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











up vote
8
down vote

favorite












Suppose I do



 grep "MyVariable = False" FormA.frm

... result1

grep "MyVariable = True" FormA.frm

... result2


How to write the grep command so that I can say something like



 grep "MyVariable = False" OR "MyVariable = True" FormA.frm









share|improve this question























  • You want to test whether a line contains Var1 = False AND Var2 = True? Or whether a file contains Var1 = False AND Var2 = True? Or something else? An example would help.
    – Mikel
    Mar 28 '12 at 15:40











  • I used AND by mistake. I meant "OR".
    – CodeBlue
    Mar 28 '12 at 15:43














up vote
8
down vote

favorite












Suppose I do



 grep "MyVariable = False" FormA.frm

... result1

grep "MyVariable = True" FormA.frm

... result2


How to write the grep command so that I can say something like



 grep "MyVariable = False" OR "MyVariable = True" FormA.frm









share|improve this question























  • You want to test whether a line contains Var1 = False AND Var2 = True? Or whether a file contains Var1 = False AND Var2 = True? Or something else? An example would help.
    – Mikel
    Mar 28 '12 at 15:40











  • I used AND by mistake. I meant "OR".
    – CodeBlue
    Mar 28 '12 at 15:43












up vote
8
down vote

favorite









up vote
8
down vote

favorite











Suppose I do



 grep "MyVariable = False" FormA.frm

... result1

grep "MyVariable = True" FormA.frm

... result2


How to write the grep command so that I can say something like



 grep "MyVariable = False" OR "MyVariable = True" FormA.frm









share|improve this question















Suppose I do



 grep "MyVariable = False" FormA.frm

... result1

grep "MyVariable = True" FormA.frm

... result2


How to write the grep command so that I can say something like



 grep "MyVariable = False" OR "MyVariable = True" FormA.frm






grep






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 17 mins ago









Sparhawk

8,60363589




8,60363589










asked Mar 28 '12 at 15:20









CodeBlue

50731020




50731020











  • You want to test whether a line contains Var1 = False AND Var2 = True? Or whether a file contains Var1 = False AND Var2 = True? Or something else? An example would help.
    – Mikel
    Mar 28 '12 at 15:40











  • I used AND by mistake. I meant "OR".
    – CodeBlue
    Mar 28 '12 at 15:43
















  • You want to test whether a line contains Var1 = False AND Var2 = True? Or whether a file contains Var1 = False AND Var2 = True? Or something else? An example would help.
    – Mikel
    Mar 28 '12 at 15:40











  • I used AND by mistake. I meant "OR".
    – CodeBlue
    Mar 28 '12 at 15:43















You want to test whether a line contains Var1 = False AND Var2 = True? Or whether a file contains Var1 = False AND Var2 = True? Or something else? An example would help.
– Mikel
Mar 28 '12 at 15:40





You want to test whether a line contains Var1 = False AND Var2 = True? Or whether a file contains Var1 = False AND Var2 = True? Or something else? An example would help.
– Mikel
Mar 28 '12 at 15:40













I used AND by mistake. I meant "OR".
– CodeBlue
Mar 28 '12 at 15:43




I used AND by mistake. I meant "OR".
– CodeBlue
Mar 28 '12 at 15:43










4 Answers
4






active

oldest

votes

















up vote
10
down vote



accepted










What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".



Use "extended grep" and the OR operator (|).



grep -E 'MyVariable = False|MyVariable = True' FormA.frm





share|improve this answer
















  • 1




    Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
    – CodeBlue
    Mar 28 '12 at 15:40










  • Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
    – CodeBlue
    Mar 28 '12 at 15:41






  • 1




    @CodeBlue: you should get used to this: almost everything is case sensitive in Unix
    – enzotib
    Mar 28 '12 at 16:00










  • Ok thanks @enzotib . I come from a Windows background.
    – CodeBlue
    Mar 28 '12 at 16:03










  • It also works with egrep (which I use) instead of grep -E which is the more canonical.
    – Arcege
    Mar 28 '12 at 16:58

















up vote
3
down vote













You should use



grep "MyVariable = (False|True)" FormA.frm


where the | sequence mean an alternative, and the delimiters ( and ) are for grouping.






share|improve this answer




















  • Yup, this also works, although it is a bit confusing to me. Thanks.
    – CodeBlue
    Mar 28 '12 at 15:47

















up vote
1
down vote













You can simply do



grep -E "MyVariable = False|MyVariable = True" FormA.frm





share|improve this answer





























    up vote
    1
    down vote













    To answer in another way than what has already been said...



    You can also specify several matches to grep, by specifying the -e option several times



    % grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
    ... result1
    ... result2





    share|improve this answer






















    • It would be nice if you would write your answer using the text from the question rather than making up your own example.
      – G-Man
      Jun 13 at 14:40










    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
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f35241%2fhow-to-combine-two-grep-statements-and-display-their-results-together%23new-answer', 'question_page');

    );

    Post as a guest






























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    10
    down vote



    accepted










    What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".



    Use "extended grep" and the OR operator (|).



    grep -E 'MyVariable = False|MyVariable = True' FormA.frm





    share|improve this answer
















    • 1




      Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
      – CodeBlue
      Mar 28 '12 at 15:40










    • Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
      – CodeBlue
      Mar 28 '12 at 15:41






    • 1




      @CodeBlue: you should get used to this: almost everything is case sensitive in Unix
      – enzotib
      Mar 28 '12 at 16:00










    • Ok thanks @enzotib . I come from a Windows background.
      – CodeBlue
      Mar 28 '12 at 16:03










    • It also works with egrep (which I use) instead of grep -E which is the more canonical.
      – Arcege
      Mar 28 '12 at 16:58














    up vote
    10
    down vote



    accepted










    What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".



    Use "extended grep" and the OR operator (|).



    grep -E 'MyVariable = False|MyVariable = True' FormA.frm





    share|improve this answer
















    • 1




      Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
      – CodeBlue
      Mar 28 '12 at 15:40










    • Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
      – CodeBlue
      Mar 28 '12 at 15:41






    • 1




      @CodeBlue: you should get used to this: almost everything is case sensitive in Unix
      – enzotib
      Mar 28 '12 at 16:00










    • Ok thanks @enzotib . I come from a Windows background.
      – CodeBlue
      Mar 28 '12 at 16:03










    • It also works with egrep (which I use) instead of grep -E which is the more canonical.
      – Arcege
      Mar 28 '12 at 16:58












    up vote
    10
    down vote



    accepted







    up vote
    10
    down vote



    accepted






    What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".



    Use "extended grep" and the OR operator (|).



    grep -E 'MyVariable = False|MyVariable = True' FormA.frm





    share|improve this answer












    What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".



    Use "extended grep" and the OR operator (|).



    grep -E 'MyVariable = False|MyVariable = True' FormA.frm






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 28 '12 at 15:31









    Arcege

    16.5k33956




    16.5k33956







    • 1




      Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
      – CodeBlue
      Mar 28 '12 at 15:40










    • Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
      – CodeBlue
      Mar 28 '12 at 15:41






    • 1




      @CodeBlue: you should get used to this: almost everything is case sensitive in Unix
      – enzotib
      Mar 28 '12 at 16:00










    • Ok thanks @enzotib . I come from a Windows background.
      – CodeBlue
      Mar 28 '12 at 16:03










    • It also works with egrep (which I use) instead of grep -E which is the more canonical.
      – Arcege
      Mar 28 '12 at 16:58












    • 1




      Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
      – CodeBlue
      Mar 28 '12 at 15:40










    • Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
      – CodeBlue
      Mar 28 '12 at 15:41






    • 1




      @CodeBlue: you should get used to this: almost everything is case sensitive in Unix
      – enzotib
      Mar 28 '12 at 16:00










    • Ok thanks @enzotib . I come from a Windows background.
      – CodeBlue
      Mar 28 '12 at 16:03










    • It also works with egrep (which I use) instead of grep -E which is the more canonical.
      – Arcege
      Mar 28 '12 at 16:58







    1




    1




    Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
    – CodeBlue
    Mar 28 '12 at 15:40




    Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
    – CodeBlue
    Mar 28 '12 at 15:40












    Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
    – CodeBlue
    Mar 28 '12 at 15:41




    Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
    – CodeBlue
    Mar 28 '12 at 15:41




    1




    1




    @CodeBlue: you should get used to this: almost everything is case sensitive in Unix
    – enzotib
    Mar 28 '12 at 16:00




    @CodeBlue: you should get used to this: almost everything is case sensitive in Unix
    – enzotib
    Mar 28 '12 at 16:00












    Ok thanks @enzotib . I come from a Windows background.
    – CodeBlue
    Mar 28 '12 at 16:03




    Ok thanks @enzotib . I come from a Windows background.
    – CodeBlue
    Mar 28 '12 at 16:03












    It also works with egrep (which I use) instead of grep -E which is the more canonical.
    – Arcege
    Mar 28 '12 at 16:58




    It also works with egrep (which I use) instead of grep -E which is the more canonical.
    – Arcege
    Mar 28 '12 at 16:58












    up vote
    3
    down vote













    You should use



    grep "MyVariable = (False|True)" FormA.frm


    where the | sequence mean an alternative, and the delimiters ( and ) are for grouping.






    share|improve this answer




















    • Yup, this also works, although it is a bit confusing to me. Thanks.
      – CodeBlue
      Mar 28 '12 at 15:47














    up vote
    3
    down vote













    You should use



    grep "MyVariable = (False|True)" FormA.frm


    where the | sequence mean an alternative, and the delimiters ( and ) are for grouping.






    share|improve this answer




















    • Yup, this also works, although it is a bit confusing to me. Thanks.
      – CodeBlue
      Mar 28 '12 at 15:47












    up vote
    3
    down vote










    up vote
    3
    down vote









    You should use



    grep "MyVariable = (False|True)" FormA.frm


    where the | sequence mean an alternative, and the delimiters ( and ) are for grouping.






    share|improve this answer












    You should use



    grep "MyVariable = (False|True)" FormA.frm


    where the | sequence mean an alternative, and the delimiters ( and ) are for grouping.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 28 '12 at 15:29









    enzotib

    32.8k710292




    32.8k710292











    • Yup, this also works, although it is a bit confusing to me. Thanks.
      – CodeBlue
      Mar 28 '12 at 15:47
















    • Yup, this also works, although it is a bit confusing to me. Thanks.
      – CodeBlue
      Mar 28 '12 at 15:47















    Yup, this also works, although it is a bit confusing to me. Thanks.
    – CodeBlue
    Mar 28 '12 at 15:47




    Yup, this also works, although it is a bit confusing to me. Thanks.
    – CodeBlue
    Mar 28 '12 at 15:47










    up vote
    1
    down vote













    You can simply do



    grep -E "MyVariable = False|MyVariable = True" FormA.frm





    share|improve this answer


























      up vote
      1
      down vote













      You can simply do



      grep -E "MyVariable = False|MyVariable = True" FormA.frm





      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









        You can simply do



        grep -E "MyVariable = False|MyVariable = True" FormA.frm





        share|improve this answer














        You can simply do



        grep -E "MyVariable = False|MyVariable = True" FormA.frm






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 '12 at 15:34









        Kevin

        26.2k105897




        26.2k105897










        answered Mar 28 '12 at 15:30









        Sachin Divekar

        3,7781619




        3,7781619




















            up vote
            1
            down vote













            To answer in another way than what has already been said...



            You can also specify several matches to grep, by specifying the -e option several times



            % grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
            ... result1
            ... result2





            share|improve this answer






















            • It would be nice if you would write your answer using the text from the question rather than making up your own example.
              – G-Man
              Jun 13 at 14:40














            up vote
            1
            down vote













            To answer in another way than what has already been said...



            You can also specify several matches to grep, by specifying the -e option several times



            % grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
            ... result1
            ... result2





            share|improve this answer






















            • It would be nice if you would write your answer using the text from the question rather than making up your own example.
              – G-Man
              Jun 13 at 14:40












            up vote
            1
            down vote










            up vote
            1
            down vote









            To answer in another way than what has already been said...



            You can also specify several matches to grep, by specifying the -e option several times



            % grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
            ... result1
            ... result2





            share|improve this answer














            To answer in another way than what has already been said...



            You can also specify several matches to grep, by specifying the -e option several times



            % grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
            ... result1
            ... result2






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 13 at 14:48

























            answered Jun 13 at 14:28









            Vince

            1213




            1213











            • It would be nice if you would write your answer using the text from the question rather than making up your own example.
              – G-Man
              Jun 13 at 14:40
















            • It would be nice if you would write your answer using the text from the question rather than making up your own example.
              – G-Man
              Jun 13 at 14:40















            It would be nice if you would write your answer using the text from the question rather than making up your own example.
            – G-Man
            Jun 13 at 14:40




            It would be nice if you would write your answer using the text from the question rather than making up your own example.
            – G-Man
            Jun 13 at 14:40

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f35241%2fhow-to-combine-two-grep-statements-and-display-their-results-together%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