How to grep from tee?
Clash 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.
bash shell grep tee
migrated from serverfault.com Aug 16 at 23:18
This question came from our site for system and network administrators.
add a comment |Â
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.
bash shell grep tee
migrated from serverfault.com Aug 16 at 23:18
This question came from our site for system and network administrators.
I also triedcommand | 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
add a comment |Â
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.
bash shell grep tee
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
bash shell grep tee
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 triedcommand | 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
add a comment |Â
I also triedcommand | 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
add a comment |Â
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".
add a comment |Â
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
What does the!
at the beginning of the fourth line do? Does it negate the output ofgrep
?
â 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
add a comment |Â
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".
add a comment |Â
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".
add a comment |Â
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".
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".
answered Aug 2 at 16:46
RalfFriedl
3,7001523
3,7001523
add a comment |Â
add a comment |Â
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
What does the!
at the beginning of the fourth line do? Does it negate the output ofgrep
?
â 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
add a comment |Â
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
What does the!
at the beginning of the fourth line do? Does it negate the output ofgrep
?
â 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
add a comment |Â
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
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
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 ofgrep
?
â 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
add a comment |Â
What does the!
at the beginning of the fourth line do? Does it negate the output ofgrep
?
â 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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