How to parse pipe with multiple commands independently?
up vote
2
down vote
favorite
How can I parse output of a single command by multiple commands without truncating at each step?
For example
ls -al|grep -i something
will pass every line that has "something" in it to the next pipe which is fine, but that also means every other line in the pipe is discarded since there wont be matching the condition. What I want is to be able to operate on single pipe by many commands independently.
In this case it a pipe from Mutt which passes the whole message body. I want to get grep, sed, delete and assign each of these to bash variables maybe.
Initially what I want is to be able to assign "message id" to a variable, "subject" to another variable etc Then pass those into proper commands arguments.
Here is how it will be
MessageBodyFromMutt|grep something -Ax -Bx |grep another thing from the original message| sed some stuff from the original message| cut from here to there
Obviously the above line does not do what I want.
I want all these commands to operate on the original message body. I hope it makes sense
command-line bash pipe mutt
add a comment |
up vote
2
down vote
favorite
How can I parse output of a single command by multiple commands without truncating at each step?
For example
ls -al|grep -i something
will pass every line that has "something" in it to the next pipe which is fine, but that also means every other line in the pipe is discarded since there wont be matching the condition. What I want is to be able to operate on single pipe by many commands independently.
In this case it a pipe from Mutt which passes the whole message body. I want to get grep, sed, delete and assign each of these to bash variables maybe.
Initially what I want is to be able to assign "message id" to a variable, "subject" to another variable etc Then pass those into proper commands arguments.
Here is how it will be
MessageBodyFromMutt|grep something -Ax -Bx |grep another thing from the original message| sed some stuff from the original message| cut from here to there
Obviously the above line does not do what I want.
I want all these commands to operate on the original message body. I hope it makes sense
command-line bash pipe mutt
Trytee
. It forks your pipes (not to variables, though).
– choroba
May 29 '14 at 16:57
choraba, thanks. It seems like that is what I need but Mutt is not liking the parenthesis around the commands following tee. I tested some chains and they work in bash but Mutt pipe is complaining about such issues. Any recommendation?
– yarun can
May 30 '14 at 4:01
Mutt is probably runningsh
, notbash
. Can you configure it to run bash? Or runbash -c '...'
.
– choroba
May 30 '14 at 7:44
@choroba ok that is working. Here is what I am trying to do. So I have a command that is called "task add +sender emailbody +from" this is how I am trying to split up. "+"s are tags in taskwarrior. Do you feel like Tee can let me do that? I was thinking that I could assign them to shell vairbales but that does not seem to happen with tee.
– yarun can
May 31 '14 at 5:11
If you want to grep the original and sed the original.. Why don't you do multiple lines like cat original | grep<ENTER> cat original | sed <ENTER> e.t.c. It'd be clearer if you gave example of the data you start with and the data you want at the end via grep and sed.
– barlop
Jun 1 '14 at 18:21
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
How can I parse output of a single command by multiple commands without truncating at each step?
For example
ls -al|grep -i something
will pass every line that has "something" in it to the next pipe which is fine, but that also means every other line in the pipe is discarded since there wont be matching the condition. What I want is to be able to operate on single pipe by many commands independently.
In this case it a pipe from Mutt which passes the whole message body. I want to get grep, sed, delete and assign each of these to bash variables maybe.
Initially what I want is to be able to assign "message id" to a variable, "subject" to another variable etc Then pass those into proper commands arguments.
Here is how it will be
MessageBodyFromMutt|grep something -Ax -Bx |grep another thing from the original message| sed some stuff from the original message| cut from here to there
Obviously the above line does not do what I want.
I want all these commands to operate on the original message body. I hope it makes sense
command-line bash pipe mutt
How can I parse output of a single command by multiple commands without truncating at each step?
For example
ls -al|grep -i something
will pass every line that has "something" in it to the next pipe which is fine, but that also means every other line in the pipe is discarded since there wont be matching the condition. What I want is to be able to operate on single pipe by many commands independently.
In this case it a pipe from Mutt which passes the whole message body. I want to get grep, sed, delete and assign each of these to bash variables maybe.
Initially what I want is to be able to assign "message id" to a variable, "subject" to another variable etc Then pass those into proper commands arguments.
Here is how it will be
MessageBodyFromMutt|grep something -Ax -Bx |grep another thing from the original message| sed some stuff from the original message| cut from here to there
Obviously the above line does not do what I want.
I want all these commands to operate on the original message body. I hope it makes sense
command-line bash pipe mutt
command-line bash pipe mutt
edited Jun 1 '14 at 16:59
asked May 29 '14 at 15:55
yarun can
412626
412626
Trytee
. It forks your pipes (not to variables, though).
– choroba
May 29 '14 at 16:57
choraba, thanks. It seems like that is what I need but Mutt is not liking the parenthesis around the commands following tee. I tested some chains and they work in bash but Mutt pipe is complaining about such issues. Any recommendation?
– yarun can
May 30 '14 at 4:01
Mutt is probably runningsh
, notbash
. Can you configure it to run bash? Or runbash -c '...'
.
– choroba
May 30 '14 at 7:44
@choroba ok that is working. Here is what I am trying to do. So I have a command that is called "task add +sender emailbody +from" this is how I am trying to split up. "+"s are tags in taskwarrior. Do you feel like Tee can let me do that? I was thinking that I could assign them to shell vairbales but that does not seem to happen with tee.
– yarun can
May 31 '14 at 5:11
If you want to grep the original and sed the original.. Why don't you do multiple lines like cat original | grep<ENTER> cat original | sed <ENTER> e.t.c. It'd be clearer if you gave example of the data you start with and the data you want at the end via grep and sed.
– barlop
Jun 1 '14 at 18:21
add a comment |
Trytee
. It forks your pipes (not to variables, though).
– choroba
May 29 '14 at 16:57
choraba, thanks. It seems like that is what I need but Mutt is not liking the parenthesis around the commands following tee. I tested some chains and they work in bash but Mutt pipe is complaining about such issues. Any recommendation?
– yarun can
May 30 '14 at 4:01
Mutt is probably runningsh
, notbash
. Can you configure it to run bash? Or runbash -c '...'
.
– choroba
May 30 '14 at 7:44
@choroba ok that is working. Here is what I am trying to do. So I have a command that is called "task add +sender emailbody +from" this is how I am trying to split up. "+"s are tags in taskwarrior. Do you feel like Tee can let me do that? I was thinking that I could assign them to shell vairbales but that does not seem to happen with tee.
– yarun can
May 31 '14 at 5:11
If you want to grep the original and sed the original.. Why don't you do multiple lines like cat original | grep<ENTER> cat original | sed <ENTER> e.t.c. It'd be clearer if you gave example of the data you start with and the data you want at the end via grep and sed.
– barlop
Jun 1 '14 at 18:21
Try
tee
. It forks your pipes (not to variables, though).– choroba
May 29 '14 at 16:57
Try
tee
. It forks your pipes (not to variables, though).– choroba
May 29 '14 at 16:57
choraba, thanks. It seems like that is what I need but Mutt is not liking the parenthesis around the commands following tee. I tested some chains and they work in bash but Mutt pipe is complaining about such issues. Any recommendation?
– yarun can
May 30 '14 at 4:01
choraba, thanks. It seems like that is what I need but Mutt is not liking the parenthesis around the commands following tee. I tested some chains and they work in bash but Mutt pipe is complaining about such issues. Any recommendation?
– yarun can
May 30 '14 at 4:01
Mutt is probably running
sh
, not bash
. Can you configure it to run bash? Or run bash -c '...'
.– choroba
May 30 '14 at 7:44
Mutt is probably running
sh
, not bash
. Can you configure it to run bash? Or run bash -c '...'
.– choroba
May 30 '14 at 7:44
@choroba ok that is working. Here is what I am trying to do. So I have a command that is called "task add +sender emailbody +from" this is how I am trying to split up. "+"s are tags in taskwarrior. Do you feel like Tee can let me do that? I was thinking that I could assign them to shell vairbales but that does not seem to happen with tee.
– yarun can
May 31 '14 at 5:11
@choroba ok that is working. Here is what I am trying to do. So I have a command that is called "task add +sender emailbody +from" this is how I am trying to split up. "+"s are tags in taskwarrior. Do you feel like Tee can let me do that? I was thinking that I could assign them to shell vairbales but that does not seem to happen with tee.
– yarun can
May 31 '14 at 5:11
If you want to grep the original and sed the original.. Why don't you do multiple lines like cat original | grep<ENTER> cat original | sed <ENTER> e.t.c. It'd be clearer if you gave example of the data you start with and the data you want at the end via grep and sed.
– barlop
Jun 1 '14 at 18:21
If you want to grep the original and sed the original.. Why don't you do multiple lines like cat original | grep<ENTER> cat original | sed <ENTER> e.t.c. It'd be clearer if you gave example of the data you start with and the data you want at the end via grep and sed.
– barlop
Jun 1 '14 at 18:21
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You can save the output to a temporary file and use that file as the input for individual commands.
If the commands do not have output, you can use tee
with bash
process substitution; it would look like
MessageBodyFromMutt | tee >( command1 ) >( command2 ) >( command3 )
But since you have output, which would be mixed together, it does not help here - except if you change the commands to save the output to files.
If you cannot create a temporary file, you can save the output that you want to process multiple times in a variable, and then echo
it multiple times:
messageBody="$( MessageBodyFromMutt )"
echo "$messageBody" | command1
echo "$messageBody" | command2
echo "$messageBody" | command3
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You can save the output to a temporary file and use that file as the input for individual commands.
If the commands do not have output, you can use tee
with bash
process substitution; it would look like
MessageBodyFromMutt | tee >( command1 ) >( command2 ) >( command3 )
But since you have output, which would be mixed together, it does not help here - except if you change the commands to save the output to files.
If you cannot create a temporary file, you can save the output that you want to process multiple times in a variable, and then echo
it multiple times:
messageBody="$( MessageBodyFromMutt )"
echo "$messageBody" | command1
echo "$messageBody" | command2
echo "$messageBody" | command3
add a comment |
up vote
2
down vote
accepted
You can save the output to a temporary file and use that file as the input for individual commands.
If the commands do not have output, you can use tee
with bash
process substitution; it would look like
MessageBodyFromMutt | tee >( command1 ) >( command2 ) >( command3 )
But since you have output, which would be mixed together, it does not help here - except if you change the commands to save the output to files.
If you cannot create a temporary file, you can save the output that you want to process multiple times in a variable, and then echo
it multiple times:
messageBody="$( MessageBodyFromMutt )"
echo "$messageBody" | command1
echo "$messageBody" | command2
echo "$messageBody" | command3
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You can save the output to a temporary file and use that file as the input for individual commands.
If the commands do not have output, you can use tee
with bash
process substitution; it would look like
MessageBodyFromMutt | tee >( command1 ) >( command2 ) >( command3 )
But since you have output, which would be mixed together, it does not help here - except if you change the commands to save the output to files.
If you cannot create a temporary file, you can save the output that you want to process multiple times in a variable, and then echo
it multiple times:
messageBody="$( MessageBodyFromMutt )"
echo "$messageBody" | command1
echo "$messageBody" | command2
echo "$messageBody" | command3
You can save the output to a temporary file and use that file as the input for individual commands.
If the commands do not have output, you can use tee
with bash
process substitution; it would look like
MessageBodyFromMutt | tee >( command1 ) >( command2 ) >( command3 )
But since you have output, which would be mixed together, it does not help here - except if you change the commands to save the output to files.
If you cannot create a temporary file, you can save the output that you want to process multiple times in a variable, and then echo
it multiple times:
messageBody="$( MessageBodyFromMutt )"
echo "$messageBody" | command1
echo "$messageBody" | command2
echo "$messageBody" | command3
edited Nov 26 at 19:34
Grant Robert Smith
1032
1032
answered Aug 20 '14 at 21:29
Volker Siegel
1,038720
1,038720
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2fsuperuser.com%2fquestions%2f760301%2fhow-to-parse-pipe-with-multiple-commands-independently%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
Try
tee
. It forks your pipes (not to variables, though).– choroba
May 29 '14 at 16:57
choraba, thanks. It seems like that is what I need but Mutt is not liking the parenthesis around the commands following tee. I tested some chains and they work in bash but Mutt pipe is complaining about such issues. Any recommendation?
– yarun can
May 30 '14 at 4:01
Mutt is probably running
sh
, notbash
. Can you configure it to run bash? Or runbash -c '...'
.– choroba
May 30 '14 at 7:44
@choroba ok that is working. Here is what I am trying to do. So I have a command that is called "task add +sender emailbody +from" this is how I am trying to split up. "+"s are tags in taskwarrior. Do you feel like Tee can let me do that? I was thinking that I could assign them to shell vairbales but that does not seem to happen with tee.
– yarun can
May 31 '14 at 5:11
If you want to grep the original and sed the original.. Why don't you do multiple lines like cat original | grep<ENTER> cat original | sed <ENTER> e.t.c. It'd be clearer if you gave example of the data you start with and the data you want at the end via grep and sed.
– barlop
Jun 1 '14 at 18:21