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
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 '18 at 23:18
This question came from our site for system and network administrators.
add a comment |
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 '18 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 '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
add a comment |
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 '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 triedcommand | 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
add a comment |
I also triedcommand | 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
add a comment |
3 Answers
3
active
oldest
votes
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 |
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 '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
add a comment |
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.
New contributor
add a comment |
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
);
);
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
Required, but never shown
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
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 |
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 |
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 '18 at 16:46
RalfFriedlRalfFriedl
5,44531025
5,44531025
add a comment |
add a comment |
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 '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
add a comment |
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 '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
add a comment |
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 '18 at 16:24
mxttiemxttie
1713
1713
What does the!
at the beginning of the fourth line do? Does it negate the output ofgrep
?
– 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
add a comment |
What does the!
at the beginning of the fourth line do? Does it negate the output ofgrep
?
– 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
add a comment |
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.
New contributor
add a comment |
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.
New contributor
add a comment |
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.
New contributor
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.
New contributor
New contributor
answered 2 days ago
DKrootDKroot
1012
1012
New contributor
New contributor
add a comment |
add a comment |
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.
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
Required, but never shown
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
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
Required, but never shown
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
Required, but never shown
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
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
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