How to grep from tee?

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











up vote
0
down vote

favorite












I want to check wether the output of my command contains "rerun" (and then rerun) but I also want to display the whole output. I know that I could use one of these:



command | tee >(grep rerun)
command | grep rerun


The first one prints the whole output as expected, but I can't use it as a condition because it always returns 0. The second one only prints the lines that contain rerun, but it returns 1 if there's no match.



My usage example:



while pdflatex paper.tex | grep -E "rerun LaTeX|run Biber"; do
biber paper
done


The answers provided here also don't help because there grep always returns 0.










share|improve this question













migrated from serverfault.com Aug 16 at 23:18


This question came from our site for system and network administrators.














  • I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.
    – Max Matti
    Aug 2 at 12:54










  • So you want the whole output, the matching lines or something else? I can't get the reason for such manipulations.
    – Kondybas
    Aug 2 at 13:49










  • Yes I want the whole output, as stated in the question. There is also a reason given, by giving an exact usecase.
    – Max Matti
    Aug 3 at 11:43














up vote
0
down vote

favorite












I want to check wether the output of my command contains "rerun" (and then rerun) but I also want to display the whole output. I know that I could use one of these:



command | tee >(grep rerun)
command | grep rerun


The first one prints the whole output as expected, but I can't use it as a condition because it always returns 0. The second one only prints the lines that contain rerun, but it returns 1 if there's no match.



My usage example:



while pdflatex paper.tex | grep -E "rerun LaTeX|run Biber"; do
biber paper
done


The answers provided here also don't help because there grep always returns 0.










share|improve this question













migrated from serverfault.com Aug 16 at 23:18


This question came from our site for system and network administrators.














  • I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.
    – Max Matti
    Aug 2 at 12:54










  • So you want the whole output, the matching lines or something else? I can't get the reason for such manipulations.
    – Kondybas
    Aug 2 at 13:49










  • Yes I want the whole output, as stated in the question. There is also a reason given, by giving an exact usecase.
    – Max Matti
    Aug 3 at 11:43












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to check wether the output of my command contains "rerun" (and then rerun) but I also want to display the whole output. I know that I could use one of these:



command | tee >(grep rerun)
command | grep rerun


The first one prints the whole output as expected, but I can't use it as a condition because it always returns 0. The second one only prints the lines that contain rerun, but it returns 1 if there's no match.



My usage example:



while pdflatex paper.tex | grep -E "rerun LaTeX|run Biber"; do
biber paper
done


The answers provided here also don't help because there grep always returns 0.










share|improve this question













I want to check wether the output of my command contains "rerun" (and then rerun) but I also want to display the whole output. I know that I could use one of these:



command | tee >(grep rerun)
command | grep rerun


The first one prints the whole output as expected, but I can't use it as a condition because it always returns 0. The second one only prints the lines that contain rerun, but it returns 1 if there's no match.



My usage example:



while pdflatex paper.tex | grep -E "rerun LaTeX|run Biber"; do
biber paper
done


The answers provided here also don't help because there grep always returns 0.







bash shell grep tee






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 2 at 12:53









Max Matti

487




487




migrated from serverfault.com Aug 16 at 23:18


This question came from our site for system and network administrators.






migrated from serverfault.com Aug 16 at 23:18


This question came from our site for system and network administrators.













  • I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.
    – Max Matti
    Aug 2 at 12:54










  • So you want the whole output, the matching lines or something else? I can't get the reason for such manipulations.
    – Kondybas
    Aug 2 at 13:49










  • Yes I want the whole output, as stated in the question. There is also a reason given, by giving an exact usecase.
    – Max Matti
    Aug 3 at 11:43
















  • I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.
    – Max Matti
    Aug 2 at 12:54










  • So you want the whole output, the matching lines or something else? I can't get the reason for such manipulations.
    – Kondybas
    Aug 2 at 13:49










  • Yes I want the whole output, as stated in the question. There is also a reason given, by giving an exact usecase.
    – Max Matti
    Aug 3 at 11:43















I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.
– Max Matti
Aug 2 at 12:54




I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.
– Max Matti
Aug 2 at 12:54












So you want the whole output, the matching lines or something else? I can't get the reason for such manipulations.
– Kondybas
Aug 2 at 13:49




So you want the whole output, the matching lines or something else? I can't get the reason for such manipulations.
– Kondybas
Aug 2 at 13:49












Yes I want the whole output, as stated in the question. There is also a reason given, by giving an exact usecase.
– Max Matti
Aug 3 at 11:43




Yes I want the whole output, as stated in the question. There is also a reason given, by giving an exact usecase.
– Max Matti
Aug 3 at 11:43










2 Answers
2






active

oldest

votes

















up vote
1
down vote













Just use



command | tee outfile | grep rerun


or



while pdflatex paper.tex | tee outfile | grep -E "rerun LaTeX|run Biber"; do


You can check the status of the grep command, and you can later look at the file "output".






share|improve this answer



























    up vote
    0
    down vote













    you could tee to a file and perform the grep on the file. Then you can use the grep exit code (0 when there's a match):



    RERUN=1
    while [[ $RERUN == 1 ]] ; do
    biber paper
    ! pdflatex paper.tex | tee output.txt && grep -E -q "rerun LaTeX|run Biber" output.txt
    RERUN=$?
    done


    The ! on the 4th line inverses the exit code of the grep process because grep returns 0 when it finds a match and 1 when no match, see the grep man page:




    EXIT STATUS



     Normally the exit status is 0 if a line is selected, 1 if no lines were
    selected, and 2 if an error occurred. However, if the -q or --quiet or
    --silent is used and a line is selected, the exit status is 0 even if
    an error occurred.



    5th line puts the last exit code ($?) in the RERUN var which is used in the loop condition.



    I also added the -q option to grep to not write to stdout






    share|improve this answer




















    • What does the ! at the beginning of the fourth line do? Does it negate the output of grep?
      – Max Matti
      Aug 3 at 11:46










    • @MaxMatti sorry for the late response, i was on vacation. yes, indeed, I updated the answer to answer your comment. Does it work now?
      – mxttie
      Aug 16 at 15:31










    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%2f463090%2fhow-to-grep-from-tee%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Just use



    command | tee outfile | grep rerun


    or



    while pdflatex paper.tex | tee outfile | grep -E "rerun LaTeX|run Biber"; do


    You can check the status of the grep command, and you can later look at the file "output".






    share|improve this answer
























      up vote
      1
      down vote













      Just use



      command | tee outfile | grep rerun


      or



      while pdflatex paper.tex | tee outfile | grep -E "rerun LaTeX|run Biber"; do


      You can check the status of the grep command, and you can later look at the file "output".






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        Just use



        command | tee outfile | grep rerun


        or



        while pdflatex paper.tex | tee outfile | grep -E "rerun LaTeX|run Biber"; do


        You can check the status of the grep command, and you can later look at the file "output".






        share|improve this answer












        Just use



        command | tee outfile | grep rerun


        or



        while pdflatex paper.tex | tee outfile | grep -E "rerun LaTeX|run Biber"; do


        You can check the status of the grep command, and you can later look at the file "output".







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 2 at 16:46









        RalfFriedl

        3,7001523




        3,7001523






















            up vote
            0
            down vote













            you could tee to a file and perform the grep on the file. Then you can use the grep exit code (0 when there's a match):



            RERUN=1
            while [[ $RERUN == 1 ]] ; do
            biber paper
            ! pdflatex paper.tex | tee output.txt && grep -E -q "rerun LaTeX|run Biber" output.txt
            RERUN=$?
            done


            The ! on the 4th line inverses the exit code of the grep process because grep returns 0 when it finds a match and 1 when no match, see the grep man page:




            EXIT STATUS



             Normally the exit status is 0 if a line is selected, 1 if no lines were
            selected, and 2 if an error occurred. However, if the -q or --quiet or
            --silent is used and a line is selected, the exit status is 0 even if
            an error occurred.



            5th line puts the last exit code ($?) in the RERUN var which is used in the loop condition.



            I also added the -q option to grep to not write to stdout






            share|improve this answer




















            • What does the ! at the beginning of the fourth line do? Does it negate the output of grep?
              – Max Matti
              Aug 3 at 11:46










            • @MaxMatti sorry for the late response, i was on vacation. yes, indeed, I updated the answer to answer your comment. Does it work now?
              – mxttie
              Aug 16 at 15:31














            up vote
            0
            down vote













            you could tee to a file and perform the grep on the file. Then you can use the grep exit code (0 when there's a match):



            RERUN=1
            while [[ $RERUN == 1 ]] ; do
            biber paper
            ! pdflatex paper.tex | tee output.txt && grep -E -q "rerun LaTeX|run Biber" output.txt
            RERUN=$?
            done


            The ! on the 4th line inverses the exit code of the grep process because grep returns 0 when it finds a match and 1 when no match, see the grep man page:




            EXIT STATUS



             Normally the exit status is 0 if a line is selected, 1 if no lines were
            selected, and 2 if an error occurred. However, if the -q or --quiet or
            --silent is used and a line is selected, the exit status is 0 even if
            an error occurred.



            5th line puts the last exit code ($?) in the RERUN var which is used in the loop condition.



            I also added the -q option to grep to not write to stdout






            share|improve this answer




















            • What does the ! at the beginning of the fourth line do? Does it negate the output of grep?
              – Max Matti
              Aug 3 at 11:46










            • @MaxMatti sorry for the late response, i was on vacation. yes, indeed, I updated the answer to answer your comment. Does it work now?
              – mxttie
              Aug 16 at 15:31












            up vote
            0
            down vote










            up vote
            0
            down vote









            you could tee to a file and perform the grep on the file. Then you can use the grep exit code (0 when there's a match):



            RERUN=1
            while [[ $RERUN == 1 ]] ; do
            biber paper
            ! pdflatex paper.tex | tee output.txt && grep -E -q "rerun LaTeX|run Biber" output.txt
            RERUN=$?
            done


            The ! on the 4th line inverses the exit code of the grep process because grep returns 0 when it finds a match and 1 when no match, see the grep man page:




            EXIT STATUS



             Normally the exit status is 0 if a line is selected, 1 if no lines were
            selected, and 2 if an error occurred. However, if the -q or --quiet or
            --silent is used and a line is selected, the exit status is 0 even if
            an error occurred.



            5th line puts the last exit code ($?) in the RERUN var which is used in the loop condition.



            I also added the -q option to grep to not write to stdout






            share|improve this answer












            you could tee to a file and perform the grep on the file. Then you can use the grep exit code (0 when there's a match):



            RERUN=1
            while [[ $RERUN == 1 ]] ; do
            biber paper
            ! pdflatex paper.tex | tee output.txt && grep -E -q "rerun LaTeX|run Biber" output.txt
            RERUN=$?
            done


            The ! on the 4th line inverses the exit code of the grep process because grep returns 0 when it finds a match and 1 when no match, see the grep man page:




            EXIT STATUS



             Normally the exit status is 0 if a line is selected, 1 if no lines were
            selected, and 2 if an error occurred. However, if the -q or --quiet or
            --silent is used and a line is selected, the exit status is 0 even if
            an error occurred.



            5th line puts the last exit code ($?) in the RERUN var which is used in the loop condition.



            I also added the -q option to grep to not write to stdout







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 2 at 16:24









            mxttie

            11




            11











            • What does the ! at the beginning of the fourth line do? Does it negate the output of grep?
              – Max Matti
              Aug 3 at 11:46










            • @MaxMatti sorry for the late response, i was on vacation. yes, indeed, I updated the answer to answer your comment. Does it work now?
              – mxttie
              Aug 16 at 15:31
















            • What does the ! at the beginning of the fourth line do? Does it negate the output of grep?
              – Max Matti
              Aug 3 at 11:46










            • @MaxMatti sorry for the late response, i was on vacation. yes, indeed, I updated the answer to answer your comment. Does it work now?
              – mxttie
              Aug 16 at 15:31















            What does the ! at the beginning of the fourth line do? Does it negate the output of grep?
            – Max Matti
            Aug 3 at 11:46




            What does the ! at the beginning of the fourth line do? Does it negate the output of grep?
            – Max Matti
            Aug 3 at 11:46












            @MaxMatti sorry for the late response, i was on vacation. yes, indeed, I updated the answer to answer your comment. Does it work now?
            – mxttie
            Aug 16 at 15:31




            @MaxMatti sorry for the late response, i was on vacation. yes, indeed, I updated the answer to answer your comment. Does it work now?
            – mxttie
            Aug 16 at 15:31

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463090%2fhow-to-grep-from-tee%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