grep sentence between (and including) two patterns

Multi tool use
Multi tool use

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











up vote
2
down vote

favorite












I want to extract sentences which start with



https://www.instagram.com/p/


and end with



/


For example, I want to extract the following without the x's



××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××


I have already tried



grep "https://www.instagram.com/p/*/"


However, it is not working.







share|improve this question

























    up vote
    2
    down vote

    favorite












    I want to extract sentences which start with



    https://www.instagram.com/p/


    and end with



    /


    For example, I want to extract the following without the x's



    ××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××


    I have already tried



    grep "https://www.instagram.com/p/*/"


    However, it is not working.







    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I want to extract sentences which start with



      https://www.instagram.com/p/


      and end with



      /


      For example, I want to extract the following without the x's



      ××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××


      I have already tried



      grep "https://www.instagram.com/p/*/"


      However, it is not working.







      share|improve this question













      I want to extract sentences which start with



      https://www.instagram.com/p/


      and end with



      /


      For example, I want to extract the following without the x's



      ××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××


      I have already tried



      grep "https://www.instagram.com/p/*/"


      However, it is not working.









      share|improve this question












      share|improve this question




      share|improve this question








      edited Aug 6 at 16:38









      SivaPrasath

      3,68311636




      3,68311636









      asked Aug 6 at 16:08









      Yusuke Otsubo

      132




      132




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Try the following regular expression, https://www.instagram.com/p/[^/]+/



          #!/bin/bash
          data="××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××"
          echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'


          The magic part is [^/]+/, it grabs everything up to the next forward slash.



          Sample output from the above script.



          zb@server ~ $ ./tmp.sh 
          https://www.instagram.com/p/BRhNDg5jne7/





          share|improve this answer





















          • It works! Thank you!
            – Yusuke Otsubo
            yesterday

















          up vote
          3
          down vote













          Using grep :



          echo "××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"


          output:



          https://www.instagram.com/p/BRhNDg5jne7/





          share|improve this answer






























            up vote
            0
            down vote













            no need of perl regex You can try :



            grep -o "https://www.instagram.com/.*/"





            share|improve this answer

















            • 1




              You probably want a non-greedy match, or something like https://www.instagram.com/foo/ bar baz other stuff/ will match the entire thing. You can do it by passing -P and changing .* to .*?
              – Michael Mrozek♦
              Aug 6 at 19:04

















            up vote
            0
            down vote













            EDIT: since the question had some changes since I posted my answer, so did my understanding of it.



            If all your rows have the pattern xxxx, then all you gotta do is a regex replace with sed. I.e.:



            sed 's/xxxx*//g'


            If you first need to grep the rows, then pipe sed after grep. I.e.:



            grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'


            Depending of the real pattern you have, this approach may or may not be of use.






            share|improve this answer























            • hope you are removing, instead of printing.
              – SivaPrasath
              Aug 6 at 17:27










            • @SivaPrasath please see my edited answer.
              – Juanse Albuja
              Aug 6 at 20:48










            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%2f460859%2fgrep-sentence-between-and-including-two-patterns%23new-answer', 'question_page');

            );

            Post as a guest






























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            Try the following regular expression, https://www.instagram.com/p/[^/]+/



            #!/bin/bash
            data="××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××"
            echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'


            The magic part is [^/]+/, it grabs everything up to the next forward slash.



            Sample output from the above script.



            zb@server ~ $ ./tmp.sh 
            https://www.instagram.com/p/BRhNDg5jne7/





            share|improve this answer





















            • It works! Thank you!
              – Yusuke Otsubo
              yesterday














            up vote
            1
            down vote



            accepted










            Try the following regular expression, https://www.instagram.com/p/[^/]+/



            #!/bin/bash
            data="××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××"
            echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'


            The magic part is [^/]+/, it grabs everything up to the next forward slash.



            Sample output from the above script.



            zb@server ~ $ ./tmp.sh 
            https://www.instagram.com/p/BRhNDg5jne7/





            share|improve this answer





















            • It works! Thank you!
              – Yusuke Otsubo
              yesterday












            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            Try the following regular expression, https://www.instagram.com/p/[^/]+/



            #!/bin/bash
            data="××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××"
            echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'


            The magic part is [^/]+/, it grabs everything up to the next forward slash.



            Sample output from the above script.



            zb@server ~ $ ./tmp.sh 
            https://www.instagram.com/p/BRhNDg5jne7/





            share|improve this answer













            Try the following regular expression, https://www.instagram.com/p/[^/]+/



            #!/bin/bash
            data="××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××"
            echo "$data" | grep -o 'https://www.instagram.com/p/[^/]+/'


            The magic part is [^/]+/, it grabs everything up to the next forward slash.



            Sample output from the above script.



            zb@server ~ $ ./tmp.sh 
            https://www.instagram.com/p/BRhNDg5jne7/






            share|improve this answer













            share|improve this answer



            share|improve this answer











            answered Aug 6 at 16:18









            Zachary Brady

            3,376831




            3,376831











            • It works! Thank you!
              – Yusuke Otsubo
              yesterday
















            • It works! Thank you!
              – Yusuke Otsubo
              yesterday















            It works! Thank you!
            – Yusuke Otsubo
            yesterday




            It works! Thank you!
            – Yusuke Otsubo
            yesterday












            up vote
            3
            down vote













            Using grep :



            echo "××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"


            output:



            https://www.instagram.com/p/BRhNDg5jne7/





            share|improve this answer



























              up vote
              3
              down vote













              Using grep :



              echo "××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"


              output:



              https://www.instagram.com/p/BRhNDg5jne7/





              share|improve this answer

























                up vote
                3
                down vote










                up vote
                3
                down vote









                Using grep :



                echo "××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"


                output:



                https://www.instagram.com/p/BRhNDg5jne7/





                share|improve this answer















                Using grep :



                echo "××××××https://www.instagram.com/p/BRhNDg5jne7/××××××××" | grep -Po "(?s)(http(.*?)(/p/.*/|/Z))"


                output:



                https://www.instagram.com/p/BRhNDg5jne7/






                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Aug 6 at 18:05


























                answered Aug 6 at 16:37









                SivaPrasath

                3,68311636




                3,68311636




















                    up vote
                    0
                    down vote













                    no need of perl regex You can try :



                    grep -o "https://www.instagram.com/.*/"





                    share|improve this answer

















                    • 1




                      You probably want a non-greedy match, or something like https://www.instagram.com/foo/ bar baz other stuff/ will match the entire thing. You can do it by passing -P and changing .* to .*?
                      – Michael Mrozek♦
                      Aug 6 at 19:04














                    up vote
                    0
                    down vote













                    no need of perl regex You can try :



                    grep -o "https://www.instagram.com/.*/"





                    share|improve this answer

















                    • 1




                      You probably want a non-greedy match, or something like https://www.instagram.com/foo/ bar baz other stuff/ will match the entire thing. You can do it by passing -P and changing .* to .*?
                      – Michael Mrozek♦
                      Aug 6 at 19:04












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    no need of perl regex You can try :



                    grep -o "https://www.instagram.com/.*/"





                    share|improve this answer













                    no need of perl regex You can try :



                    grep -o "https://www.instagram.com/.*/"






                    share|improve this answer













                    share|improve this answer



                    share|improve this answer











                    answered Aug 6 at 18:08









                    ctac_

                    986116




                    986116







                    • 1




                      You probably want a non-greedy match, or something like https://www.instagram.com/foo/ bar baz other stuff/ will match the entire thing. You can do it by passing -P and changing .* to .*?
                      – Michael Mrozek♦
                      Aug 6 at 19:04












                    • 1




                      You probably want a non-greedy match, or something like https://www.instagram.com/foo/ bar baz other stuff/ will match the entire thing. You can do it by passing -P and changing .* to .*?
                      – Michael Mrozek♦
                      Aug 6 at 19:04







                    1




                    1




                    You probably want a non-greedy match, or something like https://www.instagram.com/foo/ bar baz other stuff/ will match the entire thing. You can do it by passing -P and changing .* to .*?
                    – Michael Mrozek♦
                    Aug 6 at 19:04




                    You probably want a non-greedy match, or something like https://www.instagram.com/foo/ bar baz other stuff/ will match the entire thing. You can do it by passing -P and changing .* to .*?
                    – Michael Mrozek♦
                    Aug 6 at 19:04










                    up vote
                    0
                    down vote













                    EDIT: since the question had some changes since I posted my answer, so did my understanding of it.



                    If all your rows have the pattern xxxx, then all you gotta do is a regex replace with sed. I.e.:



                    sed 's/xxxx*//g'


                    If you first need to grep the rows, then pipe sed after grep. I.e.:



                    grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'


                    Depending of the real pattern you have, this approach may or may not be of use.






                    share|improve this answer























                    • hope you are removing, instead of printing.
                      – SivaPrasath
                      Aug 6 at 17:27










                    • @SivaPrasath please see my edited answer.
                      – Juanse Albuja
                      Aug 6 at 20:48














                    up vote
                    0
                    down vote













                    EDIT: since the question had some changes since I posted my answer, so did my understanding of it.



                    If all your rows have the pattern xxxx, then all you gotta do is a regex replace with sed. I.e.:



                    sed 's/xxxx*//g'


                    If you first need to grep the rows, then pipe sed after grep. I.e.:



                    grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'


                    Depending of the real pattern you have, this approach may or may not be of use.






                    share|improve this answer























                    • hope you are removing, instead of printing.
                      – SivaPrasath
                      Aug 6 at 17:27










                    • @SivaPrasath please see my edited answer.
                      – Juanse Albuja
                      Aug 6 at 20:48












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    EDIT: since the question had some changes since I posted my answer, so did my understanding of it.



                    If all your rows have the pattern xxxx, then all you gotta do is a regex replace with sed. I.e.:



                    sed 's/xxxx*//g'


                    If you first need to grep the rows, then pipe sed after grep. I.e.:



                    grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'


                    Depending of the real pattern you have, this approach may or may not be of use.






                    share|improve this answer















                    EDIT: since the question had some changes since I posted my answer, so did my understanding of it.



                    If all your rows have the pattern xxxx, then all you gotta do is a regex replace with sed. I.e.:



                    sed 's/xxxx*//g'


                    If you first need to grep the rows, then pipe sed after grep. I.e.:



                    grep "https://www.instagram.com/p/" | sed 's/xxxx*//g'


                    Depending of the real pattern you have, this approach may or may not be of use.







                    share|improve this answer















                    share|improve this answer



                    share|improve this answer








                    edited Aug 6 at 20:48


























                    answered Aug 6 at 16:25









                    Juanse Albuja

                    63




                    63











                    • hope you are removing, instead of printing.
                      – SivaPrasath
                      Aug 6 at 17:27










                    • @SivaPrasath please see my edited answer.
                      – Juanse Albuja
                      Aug 6 at 20:48
















                    • hope you are removing, instead of printing.
                      – SivaPrasath
                      Aug 6 at 17:27










                    • @SivaPrasath please see my edited answer.
                      – Juanse Albuja
                      Aug 6 at 20:48















                    hope you are removing, instead of printing.
                    – SivaPrasath
                    Aug 6 at 17:27




                    hope you are removing, instead of printing.
                    – SivaPrasath
                    Aug 6 at 17:27












                    @SivaPrasath please see my edited answer.
                    – Juanse Albuja
                    Aug 6 at 20:48




                    @SivaPrasath please see my edited answer.
                    – Juanse Albuja
                    Aug 6 at 20:48












                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460859%2fgrep-sentence-between-and-including-two-patterns%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    4,5ZM tTSj8EQrV,qt4ZNy7CMDd6R7yO7QFvnamLl1L7cqamPB4qfchC
                    3Lfg,Ay3q3gqxxbxkf8lUwrzQtr,gNQCBJ CekND7,vC 26,Kyw MttM L1pm5OyM RT BLwK

                    Popular posts from this blog

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

                    How many registers does an x86_64 CPU actually have?

                    Displaying single band from multi-band raster using QGIS