Search and replace a substring only if another substring is not presentSearch and replace with sedHow can I...

Do the rules for the "Buying a Magic Item" downtime activity allow a character an opportunity to purchase the item later?

Does the problem of P vs NP come under the category of Operational Research?

Is law enforcement responcible for damages made by a search warrent?

Map vs. Table for index-specific operations on 2D arrays

Plotting Chebyshev polynomials using PolarPlot and FilledCurve

Backpacking with incontinence

What's the term for a group of people who enjoy literary works?

Why interlaced CRT scanning wasn't done back and forth?

Has J.J.Jameson ever found out that Peter Parker is Spider-Man?

Windows del command not working?

Can birds evolve without trees?

How to determine if result of process substitution is a file path

Overprovisioning SSD on ubuntu. How? Ubuntu 19.04 Samsung SSD 860

Why have both: BJT and FET transistors on IC output?

Deflecting lasers with lightsabers

Basic theorem proving in Mathematica?

Protect a 6 inch air hose from physical damage

Move label of an angle in Tikz

Can I say "Gesundheit" if someone is coughing?

UX writing: When to use "we"?

Accurately recalling the key - can everyone do it?

Word for pulling a punch in karate

Is Illustrator accurate for business card sizes?

Is Norway in the Single Market?



Search and replace a substring only if another substring is not present


Search and replace with sedHow can I replace a string in a file(s)?Find & replace image URLs in one file from another fileHow to replace string of the file, which is present in tar file through UNIXsed append a text with many lines after matching of multiple strings while the text remains many lines in sed commandBash while loop search and replace using sedExtracting values from a text file having | pipe as a delimiter in text file using awk command and Replacing new lines with <br> tag using sed?How to run different python scripts from command line by passing the script name as argumentchange only part of the substring using sedSed to replace lowercase and capital strings






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have the following strings in a very large document:



1.test.html#
2.test.md#
3.http://test.html#
4.https://test.md#
5.http://test.md#
6.test2.md#


Now I want to replace every .md# with .html# but ONLY if there is no http in the string. So only 2 and 6 should have a replacement. How can I do this in a shell script?










share|improve this question







New contributor



Jeroen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    0















    I have the following strings in a very large document:



    1.test.html#
    2.test.md#
    3.http://test.html#
    4.https://test.md#
    5.http://test.md#
    6.test2.md#


    Now I want to replace every .md# with .html# but ONLY if there is no http in the string. So only 2 and 6 should have a replacement. How can I do this in a shell script?










    share|improve this question







    New contributor



    Jeroen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0












      0








      0








      I have the following strings in a very large document:



      1.test.html#
      2.test.md#
      3.http://test.html#
      4.https://test.md#
      5.http://test.md#
      6.test2.md#


      Now I want to replace every .md# with .html# but ONLY if there is no http in the string. So only 2 and 6 should have a replacement. How can I do this in a shell script?










      share|improve this question







      New contributor



      Jeroen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have the following strings in a very large document:



      1.test.html#
      2.test.md#
      3.http://test.html#
      4.https://test.md#
      5.http://test.md#
      6.test2.md#


      Now I want to replace every .md# with .html# but ONLY if there is no http in the string. So only 2 and 6 should have a replacement. How can I do this in a shell script?







      shell-script sed






      share|improve this question







      New contributor



      Jeroen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question







      New contributor



      Jeroen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question






      New contributor



      Jeroen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 16 mins ago









      JeroenJeroen

      1032 bronze badges




      1032 bronze badges




      New contributor



      Jeroen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Jeroen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          1 Answer
          1






          active

          oldest

          votes


















          1














          With GNU sed. If current line (pattern space) contains http jump to end of script (b). Otherwise do search and replace.



          sed '/http/b; s/.md#/.html#/' file


          Output:




          1.test.html#
          2.test.html#
          3.http://test.html#
          4.https://test.md#
          5.http://test.md#
          6.test2.html#


          If you want to edit your file "in place" use sed's option -i.





          See: man sed






          share|improve this answer


























          • It works! Can only accept the answer in 6 minutes... Will do so then ;-)

            – Jeroen
            7 mins 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
          });


          }
          });






          Jeroen is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f533784%2fsearch-and-replace-a-substring-only-if-another-substring-is-not-present%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









          1














          With GNU sed. If current line (pattern space) contains http jump to end of script (b). Otherwise do search and replace.



          sed '/http/b; s/.md#/.html#/' file


          Output:




          1.test.html#
          2.test.html#
          3.http://test.html#
          4.https://test.md#
          5.http://test.md#
          6.test2.html#


          If you want to edit your file "in place" use sed's option -i.





          See: man sed






          share|improve this answer


























          • It works! Can only accept the answer in 6 minutes... Will do so then ;-)

            – Jeroen
            7 mins ago
















          1














          With GNU sed. If current line (pattern space) contains http jump to end of script (b). Otherwise do search and replace.



          sed '/http/b; s/.md#/.html#/' file


          Output:




          1.test.html#
          2.test.html#
          3.http://test.html#
          4.https://test.md#
          5.http://test.md#
          6.test2.html#


          If you want to edit your file "in place" use sed's option -i.





          See: man sed






          share|improve this answer


























          • It works! Can only accept the answer in 6 minutes... Will do so then ;-)

            – Jeroen
            7 mins ago














          1












          1








          1







          With GNU sed. If current line (pattern space) contains http jump to end of script (b). Otherwise do search and replace.



          sed '/http/b; s/.md#/.html#/' file


          Output:




          1.test.html#
          2.test.html#
          3.http://test.html#
          4.https://test.md#
          5.http://test.md#
          6.test2.html#


          If you want to edit your file "in place" use sed's option -i.





          See: man sed






          share|improve this answer













          With GNU sed. If current line (pattern space) contains http jump to end of script (b). Otherwise do search and replace.



          sed '/http/b; s/.md#/.html#/' file


          Output:




          1.test.html#
          2.test.html#
          3.http://test.html#
          4.https://test.md#
          5.http://test.md#
          6.test2.html#


          If you want to edit your file "in place" use sed's option -i.





          See: man sed







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 12 mins ago









          CyrusCyrus

          7,8062 gold badges12 silver badges41 bronze badges




          7,8062 gold badges12 silver badges41 bronze badges
















          • It works! Can only accept the answer in 6 minutes... Will do so then ;-)

            – Jeroen
            7 mins ago



















          • It works! Can only accept the answer in 6 minutes... Will do so then ;-)

            – Jeroen
            7 mins ago

















          It works! Can only accept the answer in 6 minutes... Will do so then ;-)

          – Jeroen
          7 mins ago





          It works! Can only accept the answer in 6 minutes... Will do so then ;-)

          – Jeroen
          7 mins ago










          Jeroen is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Jeroen is a new contributor. Be nice, and check out our Code of Conduct.













          Jeroen is a new contributor. Be nice, and check out our Code of Conduct.












          Jeroen is a new contributor. Be nice, and check out our Code of Conduct.
















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f533784%2fsearch-and-replace-a-substring-only-if-another-substring-is-not-present%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

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...