Is it possible to filter a set of lines through an external command in ed?

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











up vote
1
down vote

favorite












In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND.



However, I cannot determine how to do both simultaneously.



r 1,3w !sort
1,3w !sort: No such file or directory


Is it possible to do this in ed?







share|improve this question























    up vote
    1
    down vote

    favorite












    In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND.



    However, I cannot determine how to do both simultaneously.



    r 1,3w !sort
    1,3w !sort: No such file or directory


    Is it possible to do this in ed?







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND.



      However, I cannot determine how to do both simultaneously.



      r 1,3w !sort
      1,3w !sort: No such file or directory


      Is it possible to do this in ed?







      share|improve this question











      In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND.



      However, I cannot determine how to do both simultaneously.



      r 1,3w !sort
      1,3w !sort: No such file or directory


      Is it possible to do this in ed?









      share|improve this question










      share|improve this question




      share|improve this question









      asked May 18 at 17:47









      merlin2011

      1,58431422




      1,58431422




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote














          how to do both simultaneously




          You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.
          ed was clearly not designed to do that kind of stuff... Try vim.

          That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:


          ed -s infile


          5,8d
          4r ! ed -s infile<<<$'5,8w !sort -nnq'
          ,p
          q





          share|improve this answer




























            up vote
            0
            down vote













            The only way I found to do this requires using an external file to store the results temporarily.



            $ cat input.txt 
            13
            5
            29
            22
            45
            64
            17
            20
            69
            91
            $ ed input.txt
            29
            1,3w !sort -n > temp.txt
            8
            1,3d
            0r temp.txt
            8
            wq
            29





            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%2f444670%2fis-it-possible-to-filter-a-set-of-lines-through-an-external-command-in-ed%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote














              how to do both simultaneously




              You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.
              ed was clearly not designed to do that kind of stuff... Try vim.

              That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:


              ed -s infile


              5,8d
              4r ! ed -s infile<<<$'5,8w !sort -nnq'
              ,p
              q





              share|improve this answer

























                up vote
                1
                down vote














                how to do both simultaneously




                You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.
                ed was clearly not designed to do that kind of stuff... Try vim.

                That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:


                ed -s infile


                5,8d
                4r ! ed -s infile<<<$'5,8w !sort -nnq'
                ,p
                q





                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote










                  how to do both simultaneously




                  You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.
                  ed was clearly not designed to do that kind of stuff... Try vim.

                  That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:


                  ed -s infile


                  5,8d
                  4r ! ed -s infile<<<$'5,8w !sort -nnq'
                  ,p
                  q





                  share|improve this answer














                  how to do both simultaneously




                  You can't write lines from the text buffer to some command stdin and read its stdout back in, replacing the original lines, in one go.
                  ed was clearly not designed to do that kind of stuff... Try vim.

                  That being said, you can always use some contortions like ed inside ed, e.g. open the file, delete those lines from the text buffer, process them via another ed invocation (which reads from the original file not from the current buffer) whose output you then read into the buffer before the original range of lines:


                  ed -s infile


                  5,8d
                  4r ! ed -s infile<<<$'5,8w !sort -nnq'
                  ,p
                  q






                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered May 18 at 23:03









                  don_crissti

                  46.2k15121151




                  46.2k15121151






















                      up vote
                      0
                      down vote













                      The only way I found to do this requires using an external file to store the results temporarily.



                      $ cat input.txt 
                      13
                      5
                      29
                      22
                      45
                      64
                      17
                      20
                      69
                      91
                      $ ed input.txt
                      29
                      1,3w !sort -n > temp.txt
                      8
                      1,3d
                      0r temp.txt
                      8
                      wq
                      29





                      share|improve this answer

























                        up vote
                        0
                        down vote













                        The only way I found to do this requires using an external file to store the results temporarily.



                        $ cat input.txt 
                        13
                        5
                        29
                        22
                        45
                        64
                        17
                        20
                        69
                        91
                        $ ed input.txt
                        29
                        1,3w !sort -n > temp.txt
                        8
                        1,3d
                        0r temp.txt
                        8
                        wq
                        29





                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          The only way I found to do this requires using an external file to store the results temporarily.



                          $ cat input.txt 
                          13
                          5
                          29
                          22
                          45
                          64
                          17
                          20
                          69
                          91
                          $ ed input.txt
                          29
                          1,3w !sort -n > temp.txt
                          8
                          1,3d
                          0r temp.txt
                          8
                          wq
                          29





                          share|improve this answer













                          The only way I found to do this requires using an external file to store the results temporarily.



                          $ cat input.txt 
                          13
                          5
                          29
                          22
                          45
                          64
                          17
                          20
                          69
                          91
                          $ ed input.txt
                          29
                          1,3w !sort -n > temp.txt
                          8
                          1,3d
                          0r temp.txt
                          8
                          wq
                          29






                          share|improve this answer













                          share|improve this answer



                          share|improve this answer











                          answered May 18 at 18:00









                          merlin2011

                          1,58431422




                          1,58431422






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444670%2fis-it-possible-to-filter-a-set-of-lines-through-an-external-command-in-ed%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              Peggy Mitchell

                              Palaiologos

                              The Forum (Inglewood, California)