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










share|improve this question
























  • 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, 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










  • 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















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










share|improve this question
























  • 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, 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










  • 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













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 1 '14 at 16:59

























asked May 29 '14 at 15:55









yarun can

412626




412626












  • 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, 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










  • 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












  • 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










  • @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










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





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2fsuperuser.com%2fquestions%2f760301%2fhow-to-parse-pipe-with-multiple-commands-independently%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    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





    share|improve this answer



























      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





      share|improve this answer

























        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





        share|improve this answer














        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 26 at 19:34









        Grant Robert Smith

        1032




        1032










        answered Aug 20 '14 at 21:29









        Volker Siegel

        1,038720




        1,038720






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

             ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕