SED command to the following












-3















Using SED I would like to transform several hundred lines in a text file from:



Input example:



https://mysite.demo.com/topics/en-gb/3
https://mysite.demo.com/topics/en-gb/436
https://mysite.demo.com/topics/en-gb/9167


into



Output:



https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf


I was wondering what SED command I would use to do this?



Many thanks










share|improve this question

























  • You should include all info within the question itself, especially if the site you're linking to does not exist :-)

    – paxdiablo
    Dec 30 '18 at 23:55













  • Welcome to SO. Stack Overflow is a question and answer page for professional and enthusiastic programmers. Add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself.

    – Cyrus
    Dec 31 '18 at 6:39











  • Please take a look at: What should I do when someone answers my question?

    – Cyrus
    Dec 31 '18 at 6:40






  • 1





    sed 's|[0-9]+$|&/pdf/&.pdf|g'

    – George Vasiliou
    Dec 31 '18 at 8:31











  • IT LOOKS LIKE MY PREVIOUS COMMENTS AS WAY OF THANK YOU HAVE BEEN DELETED. REALLY APPRECIATE THE HELP EVERYBODY!!!!

    – Rhys
    Dec 31 '18 at 15:24
















-3















Using SED I would like to transform several hundred lines in a text file from:



Input example:



https://mysite.demo.com/topics/en-gb/3
https://mysite.demo.com/topics/en-gb/436
https://mysite.demo.com/topics/en-gb/9167


into



Output:



https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf


I was wondering what SED command I would use to do this?



Many thanks










share|improve this question

























  • You should include all info within the question itself, especially if the site you're linking to does not exist :-)

    – paxdiablo
    Dec 30 '18 at 23:55













  • Welcome to SO. Stack Overflow is a question and answer page for professional and enthusiastic programmers. Add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself.

    – Cyrus
    Dec 31 '18 at 6:39











  • Please take a look at: What should I do when someone answers my question?

    – Cyrus
    Dec 31 '18 at 6:40






  • 1





    sed 's|[0-9]+$|&/pdf/&.pdf|g'

    – George Vasiliou
    Dec 31 '18 at 8:31











  • IT LOOKS LIKE MY PREVIOUS COMMENTS AS WAY OF THANK YOU HAVE BEEN DELETED. REALLY APPRECIATE THE HELP EVERYBODY!!!!

    – Rhys
    Dec 31 '18 at 15:24














-3












-3








-3








Using SED I would like to transform several hundred lines in a text file from:



Input example:



https://mysite.demo.com/topics/en-gb/3
https://mysite.demo.com/topics/en-gb/436
https://mysite.demo.com/topics/en-gb/9167


into



Output:



https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf


I was wondering what SED command I would use to do this?



Many thanks










share|improve this question
















Using SED I would like to transform several hundred lines in a text file from:



Input example:



https://mysite.demo.com/topics/en-gb/3
https://mysite.demo.com/topics/en-gb/436
https://mysite.demo.com/topics/en-gb/9167


into



Output:



https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf


I was wondering what SED command I would use to do this?



Many thanks







sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 3:07









jas

7,18621732




7,18621732










asked Dec 30 '18 at 23:47









RhysRhys

7115




7115













  • You should include all info within the question itself, especially if the site you're linking to does not exist :-)

    – paxdiablo
    Dec 30 '18 at 23:55













  • Welcome to SO. Stack Overflow is a question and answer page for professional and enthusiastic programmers. Add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself.

    – Cyrus
    Dec 31 '18 at 6:39











  • Please take a look at: What should I do when someone answers my question?

    – Cyrus
    Dec 31 '18 at 6:40






  • 1





    sed 's|[0-9]+$|&/pdf/&.pdf|g'

    – George Vasiliou
    Dec 31 '18 at 8:31











  • IT LOOKS LIKE MY PREVIOUS COMMENTS AS WAY OF THANK YOU HAVE BEEN DELETED. REALLY APPRECIATE THE HELP EVERYBODY!!!!

    – Rhys
    Dec 31 '18 at 15:24



















  • You should include all info within the question itself, especially if the site you're linking to does not exist :-)

    – paxdiablo
    Dec 30 '18 at 23:55













  • Welcome to SO. Stack Overflow is a question and answer page for professional and enthusiastic programmers. Add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself.

    – Cyrus
    Dec 31 '18 at 6:39











  • Please take a look at: What should I do when someone answers my question?

    – Cyrus
    Dec 31 '18 at 6:40






  • 1





    sed 's|[0-9]+$|&/pdf/&.pdf|g'

    – George Vasiliou
    Dec 31 '18 at 8:31











  • IT LOOKS LIKE MY PREVIOUS COMMENTS AS WAY OF THANK YOU HAVE BEEN DELETED. REALLY APPRECIATE THE HELP EVERYBODY!!!!

    – Rhys
    Dec 31 '18 at 15:24

















You should include all info within the question itself, especially if the site you're linking to does not exist :-)

– paxdiablo
Dec 30 '18 at 23:55







You should include all info within the question itself, especially if the site you're linking to does not exist :-)

– paxdiablo
Dec 30 '18 at 23:55















Welcome to SO. Stack Overflow is a question and answer page for professional and enthusiastic programmers. Add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself.

– Cyrus
Dec 31 '18 at 6:39





Welcome to SO. Stack Overflow is a question and answer page for professional and enthusiastic programmers. Add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself.

– Cyrus
Dec 31 '18 at 6:39













Please take a look at: What should I do when someone answers my question?

– Cyrus
Dec 31 '18 at 6:40





Please take a look at: What should I do when someone answers my question?

– Cyrus
Dec 31 '18 at 6:40




1




1





sed 's|[0-9]+$|&/pdf/&.pdf|g'

– George Vasiliou
Dec 31 '18 at 8:31





sed 's|[0-9]+$|&/pdf/&.pdf|g'

– George Vasiliou
Dec 31 '18 at 8:31













IT LOOKS LIKE MY PREVIOUS COMMENTS AS WAY OF THANK YOU HAVE BEEN DELETED. REALLY APPRECIATE THE HELP EVERYBODY!!!!

– Rhys
Dec 31 '18 at 15:24





IT LOOKS LIKE MY PREVIOUS COMMENTS AS WAY OF THANK YOU HAVE BEEN DELETED. REALLY APPRECIATE THE HELP EVERYBODY!!!!

– Rhys
Dec 31 '18 at 15:24












2 Answers
2






active

oldest

votes


















0














Run: echo "https://mysite.demo.com/topics/en-gb/3" |
sed "s|(https://mysite.demo.com/topics/en-gb)/([0-9]+)|1/2/pdf/2.pdf|g"



Output:
https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf



Here I use sed "s|||" instead of sed "s///".






share|improve this answer































    0














    As per your sample input and expected output, this sed command would work:



    sed -E 's,(.*/)([0-9]+$),12/pdf/2.pdf,g' text_file



    Output:



    https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
    https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
    https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      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: 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%2fstackoverflow.com%2fquestions%2f53982368%2fsed-command-to-the-following%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Run: echo "https://mysite.demo.com/topics/en-gb/3" |
      sed "s|(https://mysite.demo.com/topics/en-gb)/([0-9]+)|1/2/pdf/2.pdf|g"



      Output:
      https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf



      Here I use sed "s|||" instead of sed "s///".






      share|improve this answer




























        0














        Run: echo "https://mysite.demo.com/topics/en-gb/3" |
        sed "s|(https://mysite.demo.com/topics/en-gb)/([0-9]+)|1/2/pdf/2.pdf|g"



        Output:
        https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf



        Here I use sed "s|||" instead of sed "s///".






        share|improve this answer


























          0












          0








          0







          Run: echo "https://mysite.demo.com/topics/en-gb/3" |
          sed "s|(https://mysite.demo.com/topics/en-gb)/([0-9]+)|1/2/pdf/2.pdf|g"



          Output:
          https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf



          Here I use sed "s|||" instead of sed "s///".






          share|improve this answer













          Run: echo "https://mysite.demo.com/topics/en-gb/3" |
          sed "s|(https://mysite.demo.com/topics/en-gb)/([0-9]+)|1/2/pdf/2.pdf|g"



          Output:
          https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf



          Here I use sed "s|||" instead of sed "s///".







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 31 '18 at 0:01









          Konstantin LabunKonstantin Labun

          1,7231119




          1,7231119

























              0














              As per your sample input and expected output, this sed command would work:



              sed -E 's,(.*/)([0-9]+$),12/pdf/2.pdf,g' text_file



              Output:



              https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
              https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
              https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf





              share|improve this answer




























                0














                As per your sample input and expected output, this sed command would work:



                sed -E 's,(.*/)([0-9]+$),12/pdf/2.pdf,g' text_file



                Output:



                https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
                https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
                https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf





                share|improve this answer


























                  0












                  0








                  0







                  As per your sample input and expected output, this sed command would work:



                  sed -E 's,(.*/)([0-9]+$),12/pdf/2.pdf,g' text_file



                  Output:



                  https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
                  https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
                  https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf





                  share|improve this answer













                  As per your sample input and expected output, this sed command would work:



                  sed -E 's,(.*/)([0-9]+$),12/pdf/2.pdf,g' text_file



                  Output:



                  https://mysite.demo.com/topics/en-gb/3/pdf/3.pdf
                  https://mysite.demo.com/topics/en-gb/436/pdf/436.pdf
                  https://mysite.demo.com/topics/en-gb/9167/pdf/9167.pdf






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 31 '18 at 4:37









                  User123User123

                  632413




                  632413






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • 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%2fstackoverflow.com%2fquestions%2f53982368%2fsed-command-to-the-following%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

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas