How to delete text from variable after matching some pattern?

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











up vote
0
down vote

favorite












I wish to delete some text before some pattern. For example:



VAR="This is a test script text and real script text."
PATTERN="test "


And the desired output that I want is:



NEW_VAR="script text and real script text."


Please kindly advise me as I am new to Linux scripting.









share



























    up vote
    0
    down vote

    favorite












    I wish to delete some text before some pattern. For example:



    VAR="This is a test script text and real script text."
    PATTERN="test "


    And the desired output that I want is:



    NEW_VAR="script text and real script text."


    Please kindly advise me as I am new to Linux scripting.









    share

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I wish to delete some text before some pattern. For example:



      VAR="This is a test script text and real script text."
      PATTERN="test "


      And the desired output that I want is:



      NEW_VAR="script text and real script text."


      Please kindly advise me as I am new to Linux scripting.









      share















      I wish to delete some text before some pattern. For example:



      VAR="This is a test script text and real script text."
      PATTERN="test "


      And the desired output that I want is:



      NEW_VAR="script text and real script text."


      Please kindly advise me as I am new to Linux scripting.







      shell-script string





      share














      share












      share



      share








      edited 1 min ago









      Vlastimil

      6,9251151124




      6,9251151124










      asked 5 mins ago









      JefferyLR

      93




      93




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          If you are using a shell that supports parameter expansions of type $WORD##*STR, then all you need to do is below.



          printf '%sn' "$VAR##*$PATTERN"


          To store it in the new variable, use the command substitution trick with $(..) or use printf's inherent capability to store the formatted string in a new variable



          printf -v NEW_VAR '%s' "$VAR##*$PATTERN"




          share




















            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%2f476184%2fhow-to-delete-text-from-variable-after-matching-some-pattern%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            If you are using a shell that supports parameter expansions of type $WORD##*STR, then all you need to do is below.



            printf '%sn' "$VAR##*$PATTERN"


            To store it in the new variable, use the command substitution trick with $(..) or use printf's inherent capability to store the formatted string in a new variable



            printf -v NEW_VAR '%s' "$VAR##*$PATTERN"




            share
























              up vote
              0
              down vote













              If you are using a shell that supports parameter expansions of type $WORD##*STR, then all you need to do is below.



              printf '%sn' "$VAR##*$PATTERN"


              To store it in the new variable, use the command substitution trick with $(..) or use printf's inherent capability to store the formatted string in a new variable



              printf -v NEW_VAR '%s' "$VAR##*$PATTERN"




              share






















                up vote
                0
                down vote










                up vote
                0
                down vote









                If you are using a shell that supports parameter expansions of type $WORD##*STR, then all you need to do is below.



                printf '%sn' "$VAR##*$PATTERN"


                To store it in the new variable, use the command substitution trick with $(..) or use printf's inherent capability to store the formatted string in a new variable



                printf -v NEW_VAR '%s' "$VAR##*$PATTERN"




                share












                If you are using a shell that supports parameter expansions of type $WORD##*STR, then all you need to do is below.



                printf '%sn' "$VAR##*$PATTERN"


                To store it in the new variable, use the command substitution trick with $(..) or use printf's inherent capability to store the formatted string in a new variable



                printf -v NEW_VAR '%s' "$VAR##*$PATTERN"





                share











                share


                share










                answered 3 mins ago









                Inian

                2,945822




                2,945822



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476184%2fhow-to-delete-text-from-variable-after-matching-some-pattern%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay