Multiline sed script error: newline can not be used as a string delimiter












1















I am trying to get this sed command to work:



   sed -e 
's|$API_URL|$(API_URL)|g ;
s|$API_KEY|$(API_KEY)|g ;
s|$API_SECRET|$(API_SECRET)|g ;
s|$API_SALT|$(API_SALT)|g ;
s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g ;
s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g ;
s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
./src/environments/environment.template.ts > ./src/environments/environment.ts


I am replacing placeholders in a file:



export const environment = {
api: {
url: '$API_URL',
key: '$API_KEY',
secret: '$API_SECRET',
salt: '$API_SALT'
}
};


But I get this error:




newline can not be used as a string delimiter











share|improve this question





























    1















    I am trying to get this sed command to work:



       sed -e 
    's|$API_URL|$(API_URL)|g ;
    s|$API_KEY|$(API_KEY)|g ;
    s|$API_SECRET|$(API_SECRET)|g ;
    s|$API_SALT|$(API_SALT)|g ;
    s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g ;
    s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g ;
    s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
    ./src/environments/environment.template.ts > ./src/environments/environment.ts


    I am replacing placeholders in a file:



    export const environment = {
    api: {
    url: '$API_URL',
    key: '$API_KEY',
    secret: '$API_SECRET',
    salt: '$API_SALT'
    }
    };


    But I get this error:




    newline can not be used as a string delimiter











    share|improve this question



























      1












      1








      1








      I am trying to get this sed command to work:



         sed -e 
      's|$API_URL|$(API_URL)|g ;
      s|$API_KEY|$(API_KEY)|g ;
      s|$API_SECRET|$(API_SECRET)|g ;
      s|$API_SALT|$(API_SALT)|g ;
      s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g ;
      s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g ;
      s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
      ./src/environments/environment.template.ts > ./src/environments/environment.ts


      I am replacing placeholders in a file:



      export const environment = {
      api: {
      url: '$API_URL',
      key: '$API_KEY',
      secret: '$API_SECRET',
      salt: '$API_SALT'
      }
      };


      But I get this error:




      newline can not be used as a string delimiter











      share|improve this question
















      I am trying to get this sed command to work:



         sed -e 
      's|$API_URL|$(API_URL)|g ;
      s|$API_KEY|$(API_KEY)|g ;
      s|$API_SECRET|$(API_SECRET)|g ;
      s|$API_SALT|$(API_SALT)|g ;
      s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g ;
      s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g ;
      s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
      ./src/environments/environment.template.ts > ./src/environments/environment.ts


      I am replacing placeholders in a file:



      export const environment = {
      api: {
      url: '$API_URL',
      key: '$API_KEY',
      secret: '$API_SECRET',
      salt: '$API_SALT'
      }
      };


      But I get this error:




      newline can not be used as a string delimiter








      sed text-formatting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 22 at 23:13









      Kusalananda

      135k17255422




      135k17255422










      asked Feb 22 at 22:18









      dagda1dagda1

      1154




      1154






















          1 Answer
          1






          active

          oldest

          votes


















          2














          The actual error comes from the fact that an arbitrary delimiter character may be used to delimit a regular expression when used as line addresses by prefixing the delimiter character with a backslash, as in



          @hello@d


          which would delete each line matching the regular expression hello, just like



          /hello/d


          would.



          However, newlines may not be used as a delimiter in this way. Hence the error.





          The sed script does not need the escaped newlines as it is all within a single quoted string. Remove the at the end of each line of the actual sed editing script:



          sed -e 's|$API_URL|$(API_URL)|g
          s|$API_KEY|$(API_KEY)|g
          s|$API_SECRET|$(API_SECRET)|g
          s|$API_SALT|$(API_SALT)|g
          s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g
          s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g
          s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
          infile >outfile


          Note that the ; between statements are replaced by newlines. They are only needed between statements occupying the same line, as in G;s/n/ /, for example.



          Alternatively:



          sed -e 's|$API_URL|$(API_URL)|g' 
          -e 's|$API_KEY|$(API_KEY)|g'
          -e 's|$API_SECRET|$(API_SECRET)|g'
          -e 's|$API_SALT|$(API_SALT)|g'
          -e 's|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g'
          -e 's|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g'
          -e 's|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
          infile >outfile


          Or,



          sed "s/'\$([^']*)'/'$(1)'/g" infile >outfile


          to replace anything that looks like '$something Whatever' with '$(something Whatever)'.



          Or,



          sed 's/$([A-Z_]*)/$(1)/g' infile >outfile


          to replace things that look like $SOME_THING with $(SOME_THING) (slightly stricter on the allowed characters in the variable names, but does not care about the single quotes).






          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%2f502409%2fmultiline-sed-script-error-newline-can-not-be-used-as-a-string-delimiter%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














            The actual error comes from the fact that an arbitrary delimiter character may be used to delimit a regular expression when used as line addresses by prefixing the delimiter character with a backslash, as in



            @hello@d


            which would delete each line matching the regular expression hello, just like



            /hello/d


            would.



            However, newlines may not be used as a delimiter in this way. Hence the error.





            The sed script does not need the escaped newlines as it is all within a single quoted string. Remove the at the end of each line of the actual sed editing script:



            sed -e 's|$API_URL|$(API_URL)|g
            s|$API_KEY|$(API_KEY)|g
            s|$API_SECRET|$(API_SECRET)|g
            s|$API_SALT|$(API_SALT)|g
            s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g
            s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g
            s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
            infile >outfile


            Note that the ; between statements are replaced by newlines. They are only needed between statements occupying the same line, as in G;s/n/ /, for example.



            Alternatively:



            sed -e 's|$API_URL|$(API_URL)|g' 
            -e 's|$API_KEY|$(API_KEY)|g'
            -e 's|$API_SECRET|$(API_SECRET)|g'
            -e 's|$API_SALT|$(API_SALT)|g'
            -e 's|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g'
            -e 's|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g'
            -e 's|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
            infile >outfile


            Or,



            sed "s/'\$([^']*)'/'$(1)'/g" infile >outfile


            to replace anything that looks like '$something Whatever' with '$(something Whatever)'.



            Or,



            sed 's/$([A-Z_]*)/$(1)/g' infile >outfile


            to replace things that look like $SOME_THING with $(SOME_THING) (slightly stricter on the allowed characters in the variable names, but does not care about the single quotes).






            share|improve this answer






























              2














              The actual error comes from the fact that an arbitrary delimiter character may be used to delimit a regular expression when used as line addresses by prefixing the delimiter character with a backslash, as in



              @hello@d


              which would delete each line matching the regular expression hello, just like



              /hello/d


              would.



              However, newlines may not be used as a delimiter in this way. Hence the error.





              The sed script does not need the escaped newlines as it is all within a single quoted string. Remove the at the end of each line of the actual sed editing script:



              sed -e 's|$API_URL|$(API_URL)|g
              s|$API_KEY|$(API_KEY)|g
              s|$API_SECRET|$(API_SECRET)|g
              s|$API_SALT|$(API_SALT)|g
              s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g
              s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g
              s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
              infile >outfile


              Note that the ; between statements are replaced by newlines. They are only needed between statements occupying the same line, as in G;s/n/ /, for example.



              Alternatively:



              sed -e 's|$API_URL|$(API_URL)|g' 
              -e 's|$API_KEY|$(API_KEY)|g'
              -e 's|$API_SECRET|$(API_SECRET)|g'
              -e 's|$API_SALT|$(API_SALT)|g'
              -e 's|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g'
              -e 's|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g'
              -e 's|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
              infile >outfile


              Or,



              sed "s/'\$([^']*)'/'$(1)'/g" infile >outfile


              to replace anything that looks like '$something Whatever' with '$(something Whatever)'.



              Or,



              sed 's/$([A-Z_]*)/$(1)/g' infile >outfile


              to replace things that look like $SOME_THING with $(SOME_THING) (slightly stricter on the allowed characters in the variable names, but does not care about the single quotes).






              share|improve this answer




























                2












                2








                2







                The actual error comes from the fact that an arbitrary delimiter character may be used to delimit a regular expression when used as line addresses by prefixing the delimiter character with a backslash, as in



                @hello@d


                which would delete each line matching the regular expression hello, just like



                /hello/d


                would.



                However, newlines may not be used as a delimiter in this way. Hence the error.





                The sed script does not need the escaped newlines as it is all within a single quoted string. Remove the at the end of each line of the actual sed editing script:



                sed -e 's|$API_URL|$(API_URL)|g
                s|$API_KEY|$(API_KEY)|g
                s|$API_SECRET|$(API_SECRET)|g
                s|$API_SALT|$(API_SALT)|g
                s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g
                s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g
                s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
                infile >outfile


                Note that the ; between statements are replaced by newlines. They are only needed between statements occupying the same line, as in G;s/n/ /, for example.



                Alternatively:



                sed -e 's|$API_URL|$(API_URL)|g' 
                -e 's|$API_KEY|$(API_KEY)|g'
                -e 's|$API_SECRET|$(API_SECRET)|g'
                -e 's|$API_SALT|$(API_SALT)|g'
                -e 's|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g'
                -e 's|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g'
                -e 's|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
                infile >outfile


                Or,



                sed "s/'\$([^']*)'/'$(1)'/g" infile >outfile


                to replace anything that looks like '$something Whatever' with '$(something Whatever)'.



                Or,



                sed 's/$([A-Z_]*)/$(1)/g' infile >outfile


                to replace things that look like $SOME_THING with $(SOME_THING) (slightly stricter on the allowed characters in the variable names, but does not care about the single quotes).






                share|improve this answer















                The actual error comes from the fact that an arbitrary delimiter character may be used to delimit a regular expression when used as line addresses by prefixing the delimiter character with a backslash, as in



                @hello@d


                which would delete each line matching the regular expression hello, just like



                /hello/d


                would.



                However, newlines may not be used as a delimiter in this way. Hence the error.





                The sed script does not need the escaped newlines as it is all within a single quoted string. Remove the at the end of each line of the actual sed editing script:



                sed -e 's|$API_URL|$(API_URL)|g
                s|$API_KEY|$(API_KEY)|g
                s|$API_SECRET|$(API_SECRET)|g
                s|$API_SALT|$(API_SALT)|g
                s|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g
                s|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g
                s|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
                infile >outfile


                Note that the ; between statements are replaced by newlines. They are only needed between statements occupying the same line, as in G;s/n/ /, for example.



                Alternatively:



                sed -e 's|$API_URL|$(API_URL)|g' 
                -e 's|$API_KEY|$(API_KEY)|g'
                -e 's|$API_SECRET|$(API_SECRET)|g'
                -e 's|$API_SALT|$(API_SALT)|g'
                -e 's|$STORAGE_FUNCTION|$(STORAGE_FUNCTION)|g'
                -e 's|$STORAGE_ACCOUNT|$(STORAGE_ACCOUNT)|g'
                -e 's|$STORAGE_CONTAINER|$(STORAGE_CONTAINER)|g'
                infile >outfile


                Or,



                sed "s/'\$([^']*)'/'$(1)'/g" infile >outfile


                to replace anything that looks like '$something Whatever' with '$(something Whatever)'.



                Or,



                sed 's/$([A-Z_]*)/$(1)/g' infile >outfile


                to replace things that look like $SOME_THING with $(SOME_THING) (slightly stricter on the allowed characters in the variable names, but does not care about the single quotes).







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 22 at 23:13

























                answered Feb 22 at 22:23









                KusalanandaKusalananda

                135k17255422




                135k17255422






























                    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%2f502409%2fmultiline-sed-script-error-newline-can-not-be-used-as-a-string-delimiter%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

                    How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                    is 'sed' thread safe

                    How to make a Squid Proxy server?