Grep between patterns on separate lines or single line












1














So what I would need is for grep to match only the text in between (and including) my match pattern.



So something like this (don't mind the text, it's just some garble :D):



asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg 
asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh
asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd
dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g


So what I want is something like this:
cat theabovetext|grep -E "^This * day$"
To output this:



This will be this one day
This will be this next day
This will won' not this day
This not what shoes day


So basically I want to ONLY get the text in between This and Day (including This and day) regardless of how many characters there are in between, and regardless of how many characters there are before This and after Day.
Also this needs to work even if the input is all on a single line, so this:



asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g



Has to output this:



This will be this one day This will be this next day This will won' not this day This not what shoes day



N.B. the output here is still on a single line.










share|improve this question









New contributor




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
















  • 1




    What version of grep are you looking to use? GNU with perl style regex will can do it, otherwise are you open to non-grep solutions?
    – Eric Renouf
    2 hours ago










  • grep (GNU grep) 2.20, but if it's awk or sed, I can work with those as well
    – superme
    2 hours ago










  • @superme I've attempted to emphasise important parts of your question. Feel free to re-edit if I have misread the question.
    – Sparhawk
    2 hours ago
















1














So what I would need is for grep to match only the text in between (and including) my match pattern.



So something like this (don't mind the text, it's just some garble :D):



asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg 
asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh
asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd
dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g


So what I want is something like this:
cat theabovetext|grep -E "^This * day$"
To output this:



This will be this one day
This will be this next day
This will won' not this day
This not what shoes day


So basically I want to ONLY get the text in between This and Day (including This and day) regardless of how many characters there are in between, and regardless of how many characters there are before This and after Day.
Also this needs to work even if the input is all on a single line, so this:



asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g



Has to output this:



This will be this one day This will be this next day This will won' not this day This not what shoes day



N.B. the output here is still on a single line.










share|improve this question









New contributor




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
















  • 1




    What version of grep are you looking to use? GNU with perl style regex will can do it, otherwise are you open to non-grep solutions?
    – Eric Renouf
    2 hours ago










  • grep (GNU grep) 2.20, but if it's awk or sed, I can work with those as well
    – superme
    2 hours ago










  • @superme I've attempted to emphasise important parts of your question. Feel free to re-edit if I have misread the question.
    – Sparhawk
    2 hours ago














1












1








1







So what I would need is for grep to match only the text in between (and including) my match pattern.



So something like this (don't mind the text, it's just some garble :D):



asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg 
asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh
asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd
dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g


So what I want is something like this:
cat theabovetext|grep -E "^This * day$"
To output this:



This will be this one day
This will be this next day
This will won' not this day
This not what shoes day


So basically I want to ONLY get the text in between This and Day (including This and day) regardless of how many characters there are in between, and regardless of how many characters there are before This and after Day.
Also this needs to work even if the input is all on a single line, so this:



asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g



Has to output this:



This will be this one day This will be this next day This will won' not this day This not what shoes day



N.B. the output here is still on a single line.










share|improve this question









New contributor




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











So what I would need is for grep to match only the text in between (and including) my match pattern.



So something like this (don't mind the text, it's just some garble :D):



asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg 
asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh
asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd
dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g


So what I want is something like this:
cat theabovetext|grep -E "^This * day$"
To output this:



This will be this one day
This will be this next day
This will won' not this day
This not what shoes day


So basically I want to ONLY get the text in between This and Day (including This and day) regardless of how many characters there are in between, and regardless of how many characters there are before This and after Day.
Also this needs to work even if the input is all on a single line, so this:



asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g



Has to output this:



This will be this one day This will be this next day This will won' not this day This not what shoes day



N.B. the output here is still on a single line.







grep wildcards






share|improve this question









New contributor




superme 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




superme 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








edited 2 hours ago









Sparhawk

9,27363991




9,27363991






New contributor




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









asked 2 hours ago









superme

82




82




New contributor




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





New contributor





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






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








  • 1




    What version of grep are you looking to use? GNU with perl style regex will can do it, otherwise are you open to non-grep solutions?
    – Eric Renouf
    2 hours ago










  • grep (GNU grep) 2.20, but if it's awk or sed, I can work with those as well
    – superme
    2 hours ago










  • @superme I've attempted to emphasise important parts of your question. Feel free to re-edit if I have misread the question.
    – Sparhawk
    2 hours ago














  • 1




    What version of grep are you looking to use? GNU with perl style regex will can do it, otherwise are you open to non-grep solutions?
    – Eric Renouf
    2 hours ago










  • grep (GNU grep) 2.20, but if it's awk or sed, I can work with those as well
    – superme
    2 hours ago










  • @superme I've attempted to emphasise important parts of your question. Feel free to re-edit if I have misread the question.
    – Sparhawk
    2 hours ago








1




1




What version of grep are you looking to use? GNU with perl style regex will can do it, otherwise are you open to non-grep solutions?
– Eric Renouf
2 hours ago




What version of grep are you looking to use? GNU with perl style regex will can do it, otherwise are you open to non-grep solutions?
– Eric Renouf
2 hours ago












grep (GNU grep) 2.20, but if it's awk or sed, I can work with those as well
– superme
2 hours ago




grep (GNU grep) 2.20, but if it's awk or sed, I can work with those as well
– superme
2 hours ago












@superme I've attempted to emphasise important parts of your question. Feel free to re-edit if I have misread the question.
– Sparhawk
2 hours ago




@superme I've attempted to emphasise important parts of your question. Feel free to re-edit if I have misread the question.
– Sparhawk
2 hours ago










2 Answers
2






active

oldest

votes


















1














If you want lines to be processed separately (your first example) but for multiple matches per line to be output on a single line (as in your second example), then I don't think that's possible with grep alone.



However using the same This.*?day non-greedy match in perl itself you can do



$ perl -lne 'print join " ", /This.*?day/g' theabovetext1
This will be this one day
This will be this next day
This will won' not this day
This not what shoes day


while for the single-line input



$ perl -lne 'print join " ", /This.*?day/g' theabovetext2
This will be this one day This will be this next day This will won' not this day This not what shoes day





share|improve this answer





























    1














    With GNU grep you could do the following:



    grep -o 'This.*day' theabovetext


    (note that you don't need cat since grep knows how to read files)



    The -o flag says to show only the parts of the line that match the pattern.



    I suspect other versions of grep support this flag as well, but it's not in POSIX, so it's not portable necessarily.






    share|improve this answer

















    • 1




      [me@there ~]$ grep -o 'This.*day' theabovetext This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day it only removes the first part and the last part of the gibberish it doesn't remove it in between matches
      – superme
      2 hours ago








    • 2




      You can use PCRE mode so that the quantifier can be made non-greedy grep -oP 'This.*?day' theabovetext however this will place each match on a separate line in both cases
      – steeldriver
      2 hours ago










    • @steeldriver that worked, thanks! I can't select your comment as the right answer though. One thing I'd like to know though: how come with 'This.*day' it doesn't match it, but adding the ? matches it?
      – superme
      2 hours ago










    • @superme I didn't post it as an answer because I don't believe it satisfies your requirement that "the output here is still on a single line" for the case where the input is on a single line
      – steeldriver
      2 hours ago










    • Oh sorry about that, the output can be of any format, as long as it's the selected text, I can modify it afterwards, my bad for not mentioning it, sorry :), so how come the extra ? helped?
      – superme
      1 hour 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
    });


    }
    });






    superme 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%2f491925%2fgrep-between-patterns-on-separate-lines-or-single-line%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    If you want lines to be processed separately (your first example) but for multiple matches per line to be output on a single line (as in your second example), then I don't think that's possible with grep alone.



    However using the same This.*?day non-greedy match in perl itself you can do



    $ perl -lne 'print join " ", /This.*?day/g' theabovetext1
    This will be this one day
    This will be this next day
    This will won' not this day
    This not what shoes day


    while for the single-line input



    $ perl -lne 'print join " ", /This.*?day/g' theabovetext2
    This will be this one day This will be this next day This will won' not this day This not what shoes day





    share|improve this answer


























      1














      If you want lines to be processed separately (your first example) but for multiple matches per line to be output on a single line (as in your second example), then I don't think that's possible with grep alone.



      However using the same This.*?day non-greedy match in perl itself you can do



      $ perl -lne 'print join " ", /This.*?day/g' theabovetext1
      This will be this one day
      This will be this next day
      This will won' not this day
      This not what shoes day


      while for the single-line input



      $ perl -lne 'print join " ", /This.*?day/g' theabovetext2
      This will be this one day This will be this next day This will won' not this day This not what shoes day





      share|improve this answer
























        1












        1








        1






        If you want lines to be processed separately (your first example) but for multiple matches per line to be output on a single line (as in your second example), then I don't think that's possible with grep alone.



        However using the same This.*?day non-greedy match in perl itself you can do



        $ perl -lne 'print join " ", /This.*?day/g' theabovetext1
        This will be this one day
        This will be this next day
        This will won' not this day
        This not what shoes day


        while for the single-line input



        $ perl -lne 'print join " ", /This.*?day/g' theabovetext2
        This will be this one day This will be this next day This will won' not this day This not what shoes day





        share|improve this answer












        If you want lines to be processed separately (your first example) but for multiple matches per line to be output on a single line (as in your second example), then I don't think that's possible with grep alone.



        However using the same This.*?day non-greedy match in perl itself you can do



        $ perl -lne 'print join " ", /This.*?day/g' theabovetext1
        This will be this one day
        This will be this next day
        This will won' not this day
        This not what shoes day


        while for the single-line input



        $ perl -lne 'print join " ", /This.*?day/g' theabovetext2
        This will be this one day This will be this next day This will won' not this day This not what shoes day






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        steeldriver

        34.4k35083




        34.4k35083

























            1














            With GNU grep you could do the following:



            grep -o 'This.*day' theabovetext


            (note that you don't need cat since grep knows how to read files)



            The -o flag says to show only the parts of the line that match the pattern.



            I suspect other versions of grep support this flag as well, but it's not in POSIX, so it's not portable necessarily.






            share|improve this answer

















            • 1




              [me@there ~]$ grep -o 'This.*day' theabovetext This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day it only removes the first part and the last part of the gibberish it doesn't remove it in between matches
              – superme
              2 hours ago








            • 2




              You can use PCRE mode so that the quantifier can be made non-greedy grep -oP 'This.*?day' theabovetext however this will place each match on a separate line in both cases
              – steeldriver
              2 hours ago










            • @steeldriver that worked, thanks! I can't select your comment as the right answer though. One thing I'd like to know though: how come with 'This.*day' it doesn't match it, but adding the ? matches it?
              – superme
              2 hours ago










            • @superme I didn't post it as an answer because I don't believe it satisfies your requirement that "the output here is still on a single line" for the case where the input is on a single line
              – steeldriver
              2 hours ago










            • Oh sorry about that, the output can be of any format, as long as it's the selected text, I can modify it afterwards, my bad for not mentioning it, sorry :), so how come the extra ? helped?
              – superme
              1 hour ago
















            1














            With GNU grep you could do the following:



            grep -o 'This.*day' theabovetext


            (note that you don't need cat since grep knows how to read files)



            The -o flag says to show only the parts of the line that match the pattern.



            I suspect other versions of grep support this flag as well, but it's not in POSIX, so it's not portable necessarily.






            share|improve this answer

















            • 1




              [me@there ~]$ grep -o 'This.*day' theabovetext This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day it only removes the first part and the last part of the gibberish it doesn't remove it in between matches
              – superme
              2 hours ago








            • 2




              You can use PCRE mode so that the quantifier can be made non-greedy grep -oP 'This.*?day' theabovetext however this will place each match on a separate line in both cases
              – steeldriver
              2 hours ago










            • @steeldriver that worked, thanks! I can't select your comment as the right answer though. One thing I'd like to know though: how come with 'This.*day' it doesn't match it, but adding the ? matches it?
              – superme
              2 hours ago










            • @superme I didn't post it as an answer because I don't believe it satisfies your requirement that "the output here is still on a single line" for the case where the input is on a single line
              – steeldriver
              2 hours ago










            • Oh sorry about that, the output can be of any format, as long as it's the selected text, I can modify it afterwards, my bad for not mentioning it, sorry :), so how come the extra ? helped?
              – superme
              1 hour ago














            1












            1








            1






            With GNU grep you could do the following:



            grep -o 'This.*day' theabovetext


            (note that you don't need cat since grep knows how to read files)



            The -o flag says to show only the parts of the line that match the pattern.



            I suspect other versions of grep support this flag as well, but it's not in POSIX, so it's not portable necessarily.






            share|improve this answer












            With GNU grep you could do the following:



            grep -o 'This.*day' theabovetext


            (note that you don't need cat since grep knows how to read files)



            The -o flag says to show only the parts of the line that match the pattern.



            I suspect other versions of grep support this flag as well, but it's not in POSIX, so it's not portable necessarily.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            Eric Renouf

            13.3k43050




            13.3k43050








            • 1




              [me@there ~]$ grep -o 'This.*day' theabovetext This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day it only removes the first part and the last part of the gibberish it doesn't remove it in between matches
              – superme
              2 hours ago








            • 2




              You can use PCRE mode so that the quantifier can be made non-greedy grep -oP 'This.*?day' theabovetext however this will place each match on a separate line in both cases
              – steeldriver
              2 hours ago










            • @steeldriver that worked, thanks! I can't select your comment as the right answer though. One thing I'd like to know though: how come with 'This.*day' it doesn't match it, but adding the ? matches it?
              – superme
              2 hours ago










            • @superme I didn't post it as an answer because I don't believe it satisfies your requirement that "the output here is still on a single line" for the case where the input is on a single line
              – steeldriver
              2 hours ago










            • Oh sorry about that, the output can be of any format, as long as it's the selected text, I can modify it afterwards, my bad for not mentioning it, sorry :), so how come the extra ? helped?
              – superme
              1 hour ago














            • 1




              [me@there ~]$ grep -o 'This.*day' theabovetext This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day it only removes the first part and the last part of the gibberish it doesn't remove it in between matches
              – superme
              2 hours ago








            • 2




              You can use PCRE mode so that the quantifier can be made non-greedy grep -oP 'This.*?day' theabovetext however this will place each match on a separate line in both cases
              – steeldriver
              2 hours ago










            • @steeldriver that worked, thanks! I can't select your comment as the right answer though. One thing I'd like to know though: how come with 'This.*day' it doesn't match it, but adding the ? matches it?
              – superme
              2 hours ago










            • @superme I didn't post it as an answer because I don't believe it satisfies your requirement that "the output here is still on a single line" for the case where the input is on a single line
              – steeldriver
              2 hours ago










            • Oh sorry about that, the output can be of any format, as long as it's the selected text, I can modify it afterwards, my bad for not mentioning it, sorry :), so how come the extra ? helped?
              – superme
              1 hour ago








            1




            1




            [me@there ~]$ grep -o 'This.*day' theabovetext This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day it only removes the first part and the last part of the gibberish it doesn't remove it in between matches
            – superme
            2 hours ago






            [me@there ~]$ grep -o 'This.*day' theabovetext This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day it only removes the first part and the last part of the gibberish it doesn't remove it in between matches
            – superme
            2 hours ago






            2




            2




            You can use PCRE mode so that the quantifier can be made non-greedy grep -oP 'This.*?day' theabovetext however this will place each match on a separate line in both cases
            – steeldriver
            2 hours ago




            You can use PCRE mode so that the quantifier can be made non-greedy grep -oP 'This.*?day' theabovetext however this will place each match on a separate line in both cases
            – steeldriver
            2 hours ago












            @steeldriver that worked, thanks! I can't select your comment as the right answer though. One thing I'd like to know though: how come with 'This.*day' it doesn't match it, but adding the ? matches it?
            – superme
            2 hours ago




            @steeldriver that worked, thanks! I can't select your comment as the right answer though. One thing I'd like to know though: how come with 'This.*day' it doesn't match it, but adding the ? matches it?
            – superme
            2 hours ago












            @superme I didn't post it as an answer because I don't believe it satisfies your requirement that "the output here is still on a single line" for the case where the input is on a single line
            – steeldriver
            2 hours ago




            @superme I didn't post it as an answer because I don't believe it satisfies your requirement that "the output here is still on a single line" for the case where the input is on a single line
            – steeldriver
            2 hours ago












            Oh sorry about that, the output can be of any format, as long as it's the selected text, I can modify it afterwards, my bad for not mentioning it, sorry :), so how come the extra ? helped?
            – superme
            1 hour ago




            Oh sorry about that, the output can be of any format, as long as it's the selected text, I can modify it afterwards, my bad for not mentioning it, sorry :), so how come the extra ? helped?
            – superme
            1 hour ago










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










            draft saved

            draft discarded


















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













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












            superme 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f491925%2fgrep-between-patterns-on-separate-lines-or-single-line%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

            Eastern Orthodox Church

            Zagreb

            Understanding the information contained in the Deep Space Network XML data?