Sed to discover and replace text BETWEEN two patternsSed: how to replace nextline n symbol in text...

Is it a bad idea to have an pen name with only an initial for a surname?

SQL Server has encountered occurences of I/O requests taking longer than 15 seconds

How to search for Android apps without ads?

How can Caller ID be faked?

Why can't we feel the Earth's revolution?

Is there a risk to write an invitation letter for a stranger to obtain a Czech (Schengen) visa?

Do items with curse of vanishing disappear from shulker boxes?

How to sort human readable size

What is the difference between state-based effects and effects on the stack?

Struggling to present results from long papers in short time slots

How do I become a better writer when I hate reading?

Co-worker is now managing my team. Does this mean that I'm being demoted?

Reflecting Telescope Blind Spot?

Will users know a CardView is clickable

How do credit card companies know what type of business I'm paying for?

Should I worry about having my credit pulled multiple times while car shopping?

Should I email my professor to clear up a (possibly very irrelevant) awkward misunderstanding?

Is it unethical to quit my job during company crisis?

Does the use of English words weaken diceware passphrases

Can artificial satellite positions affect tides?

Cremated People Pottery

Creating polygon with exact measurements in QGIS 3

Manager wants to hire me; HR does not. How to proceed?

How to know whether to write accidentals as sharps or flats?



Sed to discover and replace text BETWEEN two patterns


Sed: how to replace nextline n symbol in text files?replace a character from a string that is in between first and second search using sed or awkReplace one block of text with another block of text when replacement text is in a fileExtract text from one file and replace in the otherReplace content that have newlines using sedsed: replace strings with variable contentGNU Pattern Match and replace exact number of characterssed in bash script with variables returns unterminated errorSed to replace lowercase and capital stringsHow to search and replace with sed in a line with variable content in it?






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







0















Dear Stack Exchange Community,



I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.



I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.



Starting with a .js file named bobby.js that contains:



// stage content:
(lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
stuff
}


Ending with the same bobby.js file but it now has:



// stage content:
(lib.bobby = function(mode,startPosition,loop) {
stuff
}


NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.



Pseudocode describing what I think I should do:



A. Isolate the old name by looking for whatever is between this pattern::



// stage content:
(lib.


B. And this ending pattern:



= function(mode,startPosition,loop) {


C. Get the file base name itself with:



FILENAME=$(basename $1 '.js')


D. Replace old name with file base name and overwrite the file like:



sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1


BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.










share|improve this question





























    0















    Dear Stack Exchange Community,



    I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.



    I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.



    Starting with a .js file named bobby.js that contains:



    // stage content:
    (lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
    stuff
    }


    Ending with the same bobby.js file but it now has:



    // stage content:
    (lib.bobby = function(mode,startPosition,loop) {
    stuff
    }


    NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.



    Pseudocode describing what I think I should do:



    A. Isolate the old name by looking for whatever is between this pattern::



    // stage content:
    (lib.


    B. And this ending pattern:



    = function(mode,startPosition,loop) {


    C. Get the file base name itself with:



    FILENAME=$(basename $1 '.js')


    D. Replace old name with file base name and overwrite the file like:



    sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1


    BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.










    share|improve this question

























      0












      0








      0








      Dear Stack Exchange Community,



      I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.



      I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.



      Starting with a .js file named bobby.js that contains:



      // stage content:
      (lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
      stuff
      }


      Ending with the same bobby.js file but it now has:



      // stage content:
      (lib.bobby = function(mode,startPosition,loop) {
      stuff
      }


      NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.



      Pseudocode describing what I think I should do:



      A. Isolate the old name by looking for whatever is between this pattern::



      // stage content:
      (lib.


      B. And this ending pattern:



      = function(mode,startPosition,loop) {


      C. Get the file base name itself with:



      FILENAME=$(basename $1 '.js')


      D. Replace old name with file base name and overwrite the file like:



      sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1


      BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.










      share|improve this question














      Dear Stack Exchange Community,



      I see other solutions for this but I'm struggling with the regex I need to adapt them to my situation.



      I have software-generated files that have lib object member properties with names that I need to replace. I need to use sed to find whatever name of the property, and replace it with the base file name.



      Starting with a .js file named bobby.js that contains:



      // stage content:
      (lib.Scenario2IntroFigure0 = function(mode,startPosition,loop) {
      stuff
      }


      Ending with the same bobby.js file but it now has:



      // stage content:
      (lib.bobby = function(mode,startPosition,loop) {
      stuff
      }


      NOTE: Scenario2IntroFigure0 is different for every file, unfortunately.



      Pseudocode describing what I think I should do:



      A. Isolate the old name by looking for whatever is between this pattern::



      // stage content:
      (lib.


      B. And this ending pattern:



      = function(mode,startPosition,loop) {


      C. Get the file base name itself with:



      FILENAME=$(basename $1 '.js')


      D. Replace old name with file base name and overwrite the file like:



      sed -i "s/Scenario2IntroFigure0/$DA_FILE/g" $1


      BUT where "Scenario2IntroFigure0" is whatever sed found between those two patterns.







      sed






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      mishawagonmishawagon

      32




      32






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Replace $file with your $1:



          file="bobby.js"
          filename=$(basename "$file" '.js')
          sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"





          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',
            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%2f524813%2fsed-to-discover-and-replace-text-between-two-patterns%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









            0














            Replace $file with your $1:



            file="bobby.js"
            filename=$(basename "$file" '.js')
            sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"





            share|improve this answer




























              0














              Replace $file with your $1:



              file="bobby.js"
              filename=$(basename "$file" '.js')
              sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"





              share|improve this answer


























                0












                0








                0







                Replace $file with your $1:



                file="bobby.js"
                filename=$(basename "$file" '.js')
                sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"





                share|improve this answer













                Replace $file with your $1:



                file="bobby.js"
                filename=$(basename "$file" '.js')
                sed -i 's/((lib.).*( = function(mode,startPosition,loop) {)/1'"$filename"'2/' "$file"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                FreddyFreddy

                4,7531521




                4,7531521






























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524813%2fsed-to-discover-and-replace-text-between-two-patterns%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...