Run sed without -n, will the d command skip the default auto print pattern space content?












2














The document of sed states that d will:




Delete the pattern space; immediately start next cycle.




If sed is run without -n, will sed auto print the pattern space after a d command? I know at this situation, the pattern space is empty. So it's no differences to print or not. But I'm just curious.



I have this example:



root@u1804:~# seq 10 | sed -r '/5/d'
1
2
3
4
6
7
8
9
10
root@u1804:~#


As you can see, there is no 5. It's because the d caused the execution directly to the next cycle or the auto print pattern space prints an empty string?










share|improve this question





























    2














    The document of sed states that d will:




    Delete the pattern space; immediately start next cycle.




    If sed is run without -n, will sed auto print the pattern space after a d command? I know at this situation, the pattern space is empty. So it's no differences to print or not. But I'm just curious.



    I have this example:



    root@u1804:~# seq 10 | sed -r '/5/d'
    1
    2
    3
    4
    6
    7
    8
    9
    10
    root@u1804:~#


    As you can see, there is no 5. It's because the d caused the execution directly to the next cycle or the auto print pattern space prints an empty string?










    share|improve this question



























      2












      2








      2







      The document of sed states that d will:




      Delete the pattern space; immediately start next cycle.




      If sed is run without -n, will sed auto print the pattern space after a d command? I know at this situation, the pattern space is empty. So it's no differences to print or not. But I'm just curious.



      I have this example:



      root@u1804:~# seq 10 | sed -r '/5/d'
      1
      2
      3
      4
      6
      7
      8
      9
      10
      root@u1804:~#


      As you can see, there is no 5. It's because the d caused the execution directly to the next cycle or the auto print pattern space prints an empty string?










      share|improve this question















      The document of sed states that d will:




      Delete the pattern space; immediately start next cycle.




      If sed is run without -n, will sed auto print the pattern space after a d command? I know at this situation, the pattern space is empty. So it's no differences to print or not. But I'm just curious.



      I have this example:



      root@u1804:~# seq 10 | sed -r '/5/d'
      1
      2
      3
      4
      6
      7
      8
      9
      10
      root@u1804:~#


      As you can see, there is no 5. It's because the d caused the execution directly to the next cycle or the auto print pattern space prints an empty string?







      sed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      don_crissti

      49.9k15132161




      49.9k15132161










      asked 3 hours ago









      Ogrish Man

      5151415




      5151415






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Yes, d restarts the cycle so no auto-printing. It's easy to see that if you attempt to append to the pattern space after a d command e.g via G or s/^/STUFF/ nothing gets printed...

          Try seq 3 | sed '1h;2d;2G' - it will not print 1 twice even though you save it via 1h and then try to append it via 2G for the simple reason the last command is never executed - everything that follows after d (including auto-printing) is ignored (for the current address, that is).
          The standard is pretty clear:




          If no commands explicitly started a new cycle, then at the end of the
          script the pattern space shall be copied to standard output (except
          when -n is specified) and the pattern space shall be deleted.




          It's also in the manual that you quoted:




          By default sed prints all processed input (except input that has been
          modified/deleted by commands such as d)







          share|improve this answer























          • Thanks for the clarification.
            – Ogrish Man
            2 hours ago











          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492903%2frun-sed-without-n-will-the-d-command-skip-the-default-auto-print-pattern-space%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









          2














          Yes, d restarts the cycle so no auto-printing. It's easy to see that if you attempt to append to the pattern space after a d command e.g via G or s/^/STUFF/ nothing gets printed...

          Try seq 3 | sed '1h;2d;2G' - it will not print 1 twice even though you save it via 1h and then try to append it via 2G for the simple reason the last command is never executed - everything that follows after d (including auto-printing) is ignored (for the current address, that is).
          The standard is pretty clear:




          If no commands explicitly started a new cycle, then at the end of the
          script the pattern space shall be copied to standard output (except
          when -n is specified) and the pattern space shall be deleted.




          It's also in the manual that you quoted:




          By default sed prints all processed input (except input that has been
          modified/deleted by commands such as d)







          share|improve this answer























          • Thanks for the clarification.
            – Ogrish Man
            2 hours ago
















          2














          Yes, d restarts the cycle so no auto-printing. It's easy to see that if you attempt to append to the pattern space after a d command e.g via G or s/^/STUFF/ nothing gets printed...

          Try seq 3 | sed '1h;2d;2G' - it will not print 1 twice even though you save it via 1h and then try to append it via 2G for the simple reason the last command is never executed - everything that follows after d (including auto-printing) is ignored (for the current address, that is).
          The standard is pretty clear:




          If no commands explicitly started a new cycle, then at the end of the
          script the pattern space shall be copied to standard output (except
          when -n is specified) and the pattern space shall be deleted.




          It's also in the manual that you quoted:




          By default sed prints all processed input (except input that has been
          modified/deleted by commands such as d)







          share|improve this answer























          • Thanks for the clarification.
            – Ogrish Man
            2 hours ago














          2












          2








          2






          Yes, d restarts the cycle so no auto-printing. It's easy to see that if you attempt to append to the pattern space after a d command e.g via G or s/^/STUFF/ nothing gets printed...

          Try seq 3 | sed '1h;2d;2G' - it will not print 1 twice even though you save it via 1h and then try to append it via 2G for the simple reason the last command is never executed - everything that follows after d (including auto-printing) is ignored (for the current address, that is).
          The standard is pretty clear:




          If no commands explicitly started a new cycle, then at the end of the
          script the pattern space shall be copied to standard output (except
          when -n is specified) and the pattern space shall be deleted.




          It's also in the manual that you quoted:




          By default sed prints all processed input (except input that has been
          modified/deleted by commands such as d)







          share|improve this answer














          Yes, d restarts the cycle so no auto-printing. It's easy to see that if you attempt to append to the pattern space after a d command e.g via G or s/^/STUFF/ nothing gets printed...

          Try seq 3 | sed '1h;2d;2G' - it will not print 1 twice even though you save it via 1h and then try to append it via 2G for the simple reason the last command is never executed - everything that follows after d (including auto-printing) is ignored (for the current address, that is).
          The standard is pretty clear:




          If no commands explicitly started a new cycle, then at the end of the
          script the pattern space shall be copied to standard output (except
          when -n is specified) and the pattern space shall be deleted.




          It's also in the manual that you quoted:




          By default sed prints all processed input (except input that has been
          modified/deleted by commands such as d)








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 hours ago

























          answered 3 hours ago









          don_crissti

          49.9k15132161




          49.9k15132161












          • Thanks for the clarification.
            – Ogrish Man
            2 hours ago


















          • Thanks for the clarification.
            – Ogrish Man
            2 hours ago
















          Thanks for the clarification.
          – Ogrish Man
          2 hours ago




          Thanks for the clarification.
          – Ogrish Man
          2 hours ago


















          draft saved

          draft discarded




















































          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.





          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%2funix.stackexchange.com%2fquestions%2f492903%2frun-sed-without-n-will-the-d-command-skip-the-default-auto-print-pattern-space%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

          宮崎県

          濃尾地震

          シテ島