How to grep from tee?Why does adding a colon break this grep pattern?grep searchstring /etc/crontab strange behavior in BASH scriptHow do I use tee to redirect to grepUsing grep to search a fileMulticolored Greptee / sudo password cache conflict?grep two searched wordsget output and return value of grep in single operation in bashHow to use tee command with echo as per below requirement?grep till end of quote

Using "tail" to follow a file without displaying the most recent lines

Was the Stack Exchange "Happy April Fools" page fitting with the '90's code?

What Exploit Are These User Agents Trying to Use?

How to prevent "they're falling in love" trope

How can saying a song's name be a copyright violation?

How does a dynamic QR code work?

Different meanings of こわい

Could the museum Saturn V's be refitted for one more flight?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

How obscure is the use of 令 in 令和?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

What are the G forces leaving Earth orbit?

How do I exit BASH while loop using modulus operator?

Can a virus destroy the BIOS of a modern computer?

Does int main() need a declaration on C++?

Do Iron Man suits sport waste management systems?

how do we prove that a sum of two periods is still a period?

Finding the error in an argument

Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?

Can I hook these wires up to find the connection to a dead outlet?

What is a Samsaran Word™?

Blending or harmonizing

Is it a bad idea to plug the other end of ESD strap to wall ground?

ssTTsSTtRrriinInnnnNNNIiinngg



How to grep from tee?


Why does adding a colon break this grep pattern?grep searchstring /etc/crontab strange behavior in BASH scriptHow do I use tee to redirect to grepUsing grep to search a fileMulticolored Greptee / sudo password cache conflict?grep two searched wordsget output and return value of grep in single operation in bashHow to use tee command with echo as per below requirement?grep till end of quote













1















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 '18 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 '18 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 '18 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 '18 at 11:43















1















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 '18 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 '18 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 '18 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 '18 at 11:43













1












1








1








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 '18 at 12:53









Max MattiMax Matti

538




538




migrated from serverfault.com Aug 16 '18 at 23:18


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









migrated from serverfault.com Aug 16 '18 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 '18 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 '18 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 '18 at 11:43

















  • I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.

    – Max Matti
    Aug 2 '18 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 '18 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 '18 at 11:43
















I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.

– Max Matti
Aug 2 '18 at 12:54





I also tried command | tee >(echo) | grep rerun but that doesn't give any output as well.

– Max Matti
Aug 2 '18 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 '18 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 '18 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 '18 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 '18 at 11:43










3 Answers
3






active

oldest

votes


















2














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






























    0














    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 '18 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 '18 at 15:31


















    0














    If we stick with displaying stdout right away then the grep output in Process Substitution should be redirected to a file lest you get duplicated lines in the output, so you have to do for example this: command | tee >(grep rerun >/tmp/my.log).



    Once you have a file produced, all you have to do is to use [[ -s /tmp/my.log ]] as your rerun condition.






    share|improve this answer








    New contributor




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




















      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      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















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      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



























        2














        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

























          2












          2








          2







          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 '18 at 16:46









          RalfFriedlRalfFriedl

          5,44531025




          5,44531025























              0














              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 '18 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 '18 at 15:31















              0














              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 '18 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 '18 at 15:31













              0












              0








              0







              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 '18 at 16:24









              mxttiemxttie

              1713




              1713












              • What does the ! at the beginning of the fourth line do? Does it negate the output of grep?

                – Max Matti
                Aug 3 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 15:31











              0














              If we stick with displaying stdout right away then the grep output in Process Substitution should be redirected to a file lest you get duplicated lines in the output, so you have to do for example this: command | tee >(grep rerun >/tmp/my.log).



              Once you have a file produced, all you have to do is to use [[ -s /tmp/my.log ]] as your rerun condition.






              share|improve this answer








              New contributor




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
























                0














                If we stick with displaying stdout right away then the grep output in Process Substitution should be redirected to a file lest you get duplicated lines in the output, so you have to do for example this: command | tee >(grep rerun >/tmp/my.log).



                Once you have a file produced, all you have to do is to use [[ -s /tmp/my.log ]] as your rerun condition.






                share|improve this answer








                New contributor




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






















                  0












                  0








                  0







                  If we stick with displaying stdout right away then the grep output in Process Substitution should be redirected to a file lest you get duplicated lines in the output, so you have to do for example this: command | tee >(grep rerun >/tmp/my.log).



                  Once you have a file produced, all you have to do is to use [[ -s /tmp/my.log ]] as your rerun condition.






                  share|improve this answer








                  New contributor




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










                  If we stick with displaying stdout right away then the grep output in Process Substitution should be redirected to a file lest you get duplicated lines in the output, so you have to do for example this: command | tee >(grep rerun >/tmp/my.log).



                  Once you have a file produced, all you have to do is to use [[ -s /tmp/my.log ]] as your rerun condition.







                  share|improve this answer








                  New contributor




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









                  share|improve this answer



                  share|improve this answer






                  New contributor




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









                  answered 2 days ago









                  DKrootDKroot

                  1012




                  1012




                  New contributor




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





                  New contributor





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






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



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      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















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                      Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                      Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.