How do i execute multiple commands sequentially on the command line?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am pasting multiple commands into my command line and would like each line to execute and output the results sequentially.



I am pasting my input:



cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l 
cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l


and getting output:



 469005
9999
5099
25


But instead, would like each command to execute after each line break and have my output look like:



cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
469005
cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
9999
cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
5099


Not sure if this is possible but it would save me a lot of time if I don't have to map each result back to the line where it came from







share|improve this question























    up vote
    1
    down vote

    favorite












    I am pasting multiple commands into my command line and would like each line to execute and output the results sequentially.



    I am pasting my input:



    cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l 
    cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
    cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
    cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l


    and getting output:



     469005
    9999
    5099
    25


    But instead, would like each command to execute after each line break and have my output look like:



    cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
    469005
    cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
    9999
    cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
    5099


    Not sure if this is possible but it would save me a lot of time if I don't have to map each result back to the line where it came from







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am pasting multiple commands into my command line and would like each line to execute and output the results sequentially.



      I am pasting my input:



      cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l 
      cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
      cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
      cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l


      and getting output:



       469005
      9999
      5099
      25


      But instead, would like each command to execute after each line break and have my output look like:



      cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
      469005
      cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
      9999
      cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
      5099


      Not sure if this is possible but it would save me a lot of time if I don't have to map each result back to the line where it came from







      share|improve this question











      I am pasting multiple commands into my command line and would like each line to execute and output the results sequentially.



      I am pasting my input:



      cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l 
      cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
      cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
      cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l


      and getting output:



       469005
      9999
      5099
      25


      But instead, would like each command to execute after each line break and have my output look like:



      cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
      469005
      cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
      9999
      cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
      5099


      Not sure if this is possible but it would save me a lot of time if I don't have to map each result back to the line where it came from









      share|improve this question










      share|improve this question




      share|improve this question









      asked May 18 at 12:58









      Kamilski81

      1063




      1063




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote













          That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.



          What you could do, would be to use set -v or set -x to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the greps:



          for pattern in 'type_of_record_new creating' 
          'type_of_record_modification found 1'
          'type_of_record_modification found 0'
          'type_of_record_inactivation found 1'
          do
          printf "%s:n%10d" "$pattern"
          grep -c -e "$pattern" type_of_record.txt
          done


          That would give output like this



          type_of_record_new creating: 469005
          type_of_record_modification found 1: 9999


          though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d for the number of lines:



          for pattern in ...
          do
          printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
          done





          share|improve this answer






























            up vote
            0
            down vote













            Just paste your clipboard into a heredoc:



            $ sh -v << EOF
            > cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
            > cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
            > cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
            > cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
            > EOF
            cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
            cat: type_of_record.txt: No such file or directory
            0
            cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
            cat: type_of_record.txt: No such file or directory
            0
            cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
            cat: type_of_record.txt: No such file or directory
            0
            cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
            cat: type_of_record.txt: No such file or directory
            0


            In the above, I typed 'sh -v << EOF', then pasted the code from your question into the terminal, and then hit return and typed 'EOF'. If you do this sort of thing, make sure you carefully review the text you're pasting. You will probably want to quote the delimiter (eg sh << 'EOF') to avoid interpolation of any of the pasted text, but that's not necessary in this case.



            But note that in this particular case, it seems better to use awk to count the matching records so that you only need to make one pass through the file.






            share|improve this answer






























              up vote
              0
              down vote













              Using echo might do it



              First, you would literally echo the command as a string, using single-quotes, then



              Second, you would echo the command using double-quotes, which will execute the command



              echo '$(date)'; echo "$(date)"


              which gives



              robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
              $(date)
              Fri May 18 07:30:27 PDT 2018





              share|improve this answer





















                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',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                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%2f444594%2fhow-do-i-execute-multiple-commands-sequentially-on-the-command-line%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                2
                down vote













                That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.



                What you could do, would be to use set -v or set -x to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the greps:



                for pattern in 'type_of_record_new creating' 
                'type_of_record_modification found 1'
                'type_of_record_modification found 0'
                'type_of_record_inactivation found 1'
                do
                printf "%s:n%10d" "$pattern"
                grep -c -e "$pattern" type_of_record.txt
                done


                That would give output like this



                type_of_record_new creating: 469005
                type_of_record_modification found 1: 9999


                though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d for the number of lines:



                for pattern in ...
                do
                printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
                done





                share|improve this answer



























                  up vote
                  2
                  down vote













                  That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.



                  What you could do, would be to use set -v or set -x to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the greps:



                  for pattern in 'type_of_record_new creating' 
                  'type_of_record_modification found 1'
                  'type_of_record_modification found 0'
                  'type_of_record_inactivation found 1'
                  do
                  printf "%s:n%10d" "$pattern"
                  grep -c -e "$pattern" type_of_record.txt
                  done


                  That would give output like this



                  type_of_record_new creating: 469005
                  type_of_record_modification found 1: 9999


                  though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d for the number of lines:



                  for pattern in ...
                  do
                  printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
                  done





                  share|improve this answer

























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.



                    What you could do, would be to use set -v or set -x to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the greps:



                    for pattern in 'type_of_record_new creating' 
                    'type_of_record_modification found 1'
                    'type_of_record_modification found 0'
                    'type_of_record_inactivation found 1'
                    do
                    printf "%s:n%10d" "$pattern"
                    grep -c -e "$pattern" type_of_record.txt
                    done


                    That would give output like this



                    type_of_record_new creating: 469005
                    type_of_record_modification found 1: 9999


                    though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d for the number of lines:



                    for pattern in ...
                    do
                    printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
                    done





                    share|improve this answer















                    That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.



                    What you could do, would be to use set -v or set -x to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the greps:



                    for pattern in 'type_of_record_new creating' 
                    'type_of_record_modification found 1'
                    'type_of_record_modification found 0'
                    'type_of_record_inactivation found 1'
                    do
                    printf "%s:n%10d" "$pattern"
                    grep -c -e "$pattern" type_of_record.txt
                    done


                    That would give output like this



                    type_of_record_new creating: 469005
                    type_of_record_modification found 1: 9999


                    though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d for the number of lines:



                    for pattern in ...
                    do
                    printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
                    done






                    share|improve this answer















                    share|improve this answer



                    share|improve this answer








                    edited May 18 at 13:54









                    Jeff Schaller

                    31.1k846105




                    31.1k846105











                    answered May 18 at 13:30









                    ilkkachu

                    48.1k669133




                    48.1k669133






















                        up vote
                        0
                        down vote













                        Just paste your clipboard into a heredoc:



                        $ sh -v << EOF
                        > cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
                        > cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
                        > cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
                        > cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
                        > EOF
                        cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
                        cat: type_of_record.txt: No such file or directory
                        0
                        cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
                        cat: type_of_record.txt: No such file or directory
                        0
                        cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
                        cat: type_of_record.txt: No such file or directory
                        0
                        cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
                        cat: type_of_record.txt: No such file or directory
                        0


                        In the above, I typed 'sh -v << EOF', then pasted the code from your question into the terminal, and then hit return and typed 'EOF'. If you do this sort of thing, make sure you carefully review the text you're pasting. You will probably want to quote the delimiter (eg sh << 'EOF') to avoid interpolation of any of the pasted text, but that's not necessary in this case.



                        But note that in this particular case, it seems better to use awk to count the matching records so that you only need to make one pass through the file.






                        share|improve this answer



























                          up vote
                          0
                          down vote













                          Just paste your clipboard into a heredoc:



                          $ sh -v << EOF
                          > cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
                          > cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
                          > cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
                          > cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
                          > EOF
                          cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
                          cat: type_of_record.txt: No such file or directory
                          0
                          cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
                          cat: type_of_record.txt: No such file or directory
                          0
                          cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
                          cat: type_of_record.txt: No such file or directory
                          0
                          cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
                          cat: type_of_record.txt: No such file or directory
                          0


                          In the above, I typed 'sh -v << EOF', then pasted the code from your question into the terminal, and then hit return and typed 'EOF'. If you do this sort of thing, make sure you carefully review the text you're pasting. You will probably want to quote the delimiter (eg sh << 'EOF') to avoid interpolation of any of the pasted text, but that's not necessary in this case.



                          But note that in this particular case, it seems better to use awk to count the matching records so that you only need to make one pass through the file.






                          share|improve this answer

























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            Just paste your clipboard into a heredoc:



                            $ sh -v << EOF
                            > cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
                            > cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
                            > cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
                            > cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
                            > EOF
                            cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
                            cat: type_of_record.txt: No such file or directory
                            0
                            cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
                            cat: type_of_record.txt: No such file or directory
                            0
                            cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
                            cat: type_of_record.txt: No such file or directory
                            0
                            cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
                            cat: type_of_record.txt: No such file or directory
                            0


                            In the above, I typed 'sh -v << EOF', then pasted the code from your question into the terminal, and then hit return and typed 'EOF'. If you do this sort of thing, make sure you carefully review the text you're pasting. You will probably want to quote the delimiter (eg sh << 'EOF') to avoid interpolation of any of the pasted text, but that's not necessary in this case.



                            But note that in this particular case, it seems better to use awk to count the matching records so that you only need to make one pass through the file.






                            share|improve this answer















                            Just paste your clipboard into a heredoc:



                            $ sh -v << EOF
                            > cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
                            > cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
                            > cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
                            > cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
                            > EOF
                            cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
                            cat: type_of_record.txt: No such file or directory
                            0
                            cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
                            cat: type_of_record.txt: No such file or directory
                            0
                            cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
                            cat: type_of_record.txt: No such file or directory
                            0
                            cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
                            cat: type_of_record.txt: No such file or directory
                            0


                            In the above, I typed 'sh -v << EOF', then pasted the code from your question into the terminal, and then hit return and typed 'EOF'. If you do this sort of thing, make sure you carefully review the text you're pasting. You will probably want to quote the delimiter (eg sh << 'EOF') to avoid interpolation of any of the pasted text, but that's not necessary in this case.



                            But note that in this particular case, it seems better to use awk to count the matching records so that you only need to make one pass through the file.







                            share|improve this answer















                            share|improve this answer



                            share|improve this answer








                            edited May 18 at 14:01


























                            answered May 18 at 13:56









                            William Pursell

                            2,01911111




                            2,01911111




















                                up vote
                                0
                                down vote













                                Using echo might do it



                                First, you would literally echo the command as a string, using single-quotes, then



                                Second, you would echo the command using double-quotes, which will execute the command



                                echo '$(date)'; echo "$(date)"


                                which gives



                                robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
                                $(date)
                                Fri May 18 07:30:27 PDT 2018





                                share|improve this answer

























                                  up vote
                                  0
                                  down vote













                                  Using echo might do it



                                  First, you would literally echo the command as a string, using single-quotes, then



                                  Second, you would echo the command using double-quotes, which will execute the command



                                  echo '$(date)'; echo "$(date)"


                                  which gives



                                  robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
                                  $(date)
                                  Fri May 18 07:30:27 PDT 2018





                                  share|improve this answer























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    Using echo might do it



                                    First, you would literally echo the command as a string, using single-quotes, then



                                    Second, you would echo the command using double-quotes, which will execute the command



                                    echo '$(date)'; echo "$(date)"


                                    which gives



                                    robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
                                    $(date)
                                    Fri May 18 07:30:27 PDT 2018





                                    share|improve this answer













                                    Using echo might do it



                                    First, you would literally echo the command as a string, using single-quotes, then



                                    Second, you would echo the command using double-quotes, which will execute the command



                                    echo '$(date)'; echo "$(date)"


                                    which gives



                                    robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
                                    $(date)
                                    Fri May 18 07:30:27 PDT 2018






                                    share|improve this answer













                                    share|improve this answer



                                    share|improve this answer











                                    answered May 18 at 14:34









                                    mrflash818

                                    16117




                                    16117






















                                         

                                        draft saved


                                        draft discarded


























                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444594%2fhow-do-i-execute-multiple-commands-sequentially-on-the-command-line%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Popular posts from this blog

                                        How to check contact read email or not when send email to Individual?

                                        Displaying single band from multi-band raster using QGIS

                                        How many registers does an x86_64 CPU actually have?