match string but only output lines below it + not the matched string itself












-1















I need to find a way to select the lines below a specified string, in this case, the string containing the function "y" - but I don't want to select the string "y" itself, in case there are multiple lines under each other with "y".



So what I basically want is to select all of the lines containing "new o" but I DON'T want to select a "new o" that is right above the string "y(", here is what I'm getting at.



I have a file containing this;



new o85 = x(-1.3);
y(o85, 12.0, 91.2, 5);
y(o85, 12.0, 91.2, 6);
y(o85, 12.0, 91.2, 7);
new o86 = x(-1.3);
new o87 = x(-1.3);
y(o87, 12.0, 91.2, 9);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o90 = x(-1.3);
y(o90, 12.0, 91.2, 3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o96 = x(-1.3);
y(o96, 12.0, 91.2, 3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);


I want to select these specific lines;



new o86 = x(-1.3);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);


How would I go on about doing something like this?

I tried to find duplicate questions but I was not entirely sure what to search for, if it is duplicated, I apologize.



Thanks in advance.










share|improve this question

























  • Unclear. new o86 = x(-1.3); is right under y(, why did you selected that?

    – Tiw
    Jan 19 at 12:07











  • Because it is not directly above y(, it has no "connection" to y( so to speak.

    – yoranus
    Jan 19 at 12:15
















-1















I need to find a way to select the lines below a specified string, in this case, the string containing the function "y" - but I don't want to select the string "y" itself, in case there are multiple lines under each other with "y".



So what I basically want is to select all of the lines containing "new o" but I DON'T want to select a "new o" that is right above the string "y(", here is what I'm getting at.



I have a file containing this;



new o85 = x(-1.3);
y(o85, 12.0, 91.2, 5);
y(o85, 12.0, 91.2, 6);
y(o85, 12.0, 91.2, 7);
new o86 = x(-1.3);
new o87 = x(-1.3);
y(o87, 12.0, 91.2, 9);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o90 = x(-1.3);
y(o90, 12.0, 91.2, 3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o96 = x(-1.3);
y(o96, 12.0, 91.2, 3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);


I want to select these specific lines;



new o86 = x(-1.3);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);


How would I go on about doing something like this?

I tried to find duplicate questions but I was not entirely sure what to search for, if it is duplicated, I apologize.



Thanks in advance.










share|improve this question

























  • Unclear. new o86 = x(-1.3); is right under y(, why did you selected that?

    – Tiw
    Jan 19 at 12:07











  • Because it is not directly above y(, it has no "connection" to y( so to speak.

    – yoranus
    Jan 19 at 12:15














-1












-1








-1








I need to find a way to select the lines below a specified string, in this case, the string containing the function "y" - but I don't want to select the string "y" itself, in case there are multiple lines under each other with "y".



So what I basically want is to select all of the lines containing "new o" but I DON'T want to select a "new o" that is right above the string "y(", here is what I'm getting at.



I have a file containing this;



new o85 = x(-1.3);
y(o85, 12.0, 91.2, 5);
y(o85, 12.0, 91.2, 6);
y(o85, 12.0, 91.2, 7);
new o86 = x(-1.3);
new o87 = x(-1.3);
y(o87, 12.0, 91.2, 9);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o90 = x(-1.3);
y(o90, 12.0, 91.2, 3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o96 = x(-1.3);
y(o96, 12.0, 91.2, 3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);


I want to select these specific lines;



new o86 = x(-1.3);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);


How would I go on about doing something like this?

I tried to find duplicate questions but I was not entirely sure what to search for, if it is duplicated, I apologize.



Thanks in advance.










share|improve this question
















I need to find a way to select the lines below a specified string, in this case, the string containing the function "y" - but I don't want to select the string "y" itself, in case there are multiple lines under each other with "y".



So what I basically want is to select all of the lines containing "new o" but I DON'T want to select a "new o" that is right above the string "y(", here is what I'm getting at.



I have a file containing this;



new o85 = x(-1.3);
y(o85, 12.0, 91.2, 5);
y(o85, 12.0, 91.2, 6);
y(o85, 12.0, 91.2, 7);
new o86 = x(-1.3);
new o87 = x(-1.3);
y(o87, 12.0, 91.2, 9);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o90 = x(-1.3);
y(o90, 12.0, 91.2, 3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o96 = x(-1.3);
y(o96, 12.0, 91.2, 3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);


I want to select these specific lines;



new o86 = x(-1.3);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);


How would I go on about doing something like this?

I tried to find duplicate questions but I was not entirely sure what to search for, if it is duplicated, I apologize.



Thanks in advance.







awk grep






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 10:18









Tiw

2,52821026




2,52821026










asked Jan 19 at 11:55









yoranusyoranus

133




133













  • Unclear. new o86 = x(-1.3); is right under y(, why did you selected that?

    – Tiw
    Jan 19 at 12:07











  • Because it is not directly above y(, it has no "connection" to y( so to speak.

    – yoranus
    Jan 19 at 12:15



















  • Unclear. new o86 = x(-1.3); is right under y(, why did you selected that?

    – Tiw
    Jan 19 at 12:07











  • Because it is not directly above y(, it has no "connection" to y( so to speak.

    – yoranus
    Jan 19 at 12:15

















Unclear. new o86 = x(-1.3); is right under y(, why did you selected that?

– Tiw
Jan 19 at 12:07





Unclear. new o86 = x(-1.3); is right under y(, why did you selected that?

– Tiw
Jan 19 at 12:07













Because it is not directly above y(, it has no "connection" to y( so to speak.

– yoranus
Jan 19 at 12:15





Because it is not directly above y(, it has no "connection" to y( so to speak.

– yoranus
Jan 19 at 12:15












2 Answers
2






active

oldest

votes


















0














GNU grep:



grep -zoP 'new o.*?(n|$)(?!y()'


or this:



grep -zoP 'new o.*?;(?!ny()'


GNU awk:



$ awk -v RS="n*y[^)]*);n*" -F"n" 'NF>1{for(i=1;i<NF;i++) print $i}' file
new o86 = x(-1.3);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o97 = x(-1.3);
new o98 = x(-1.3);


For windows carriage return (rn) ending files:



awk -v RS="[rn]*y[^)]*);[rn]*" -F"[rn]+" 'NF>1{for(i=1;i<NF;i++) print $i}'





share|improve this answer


























  • Hey, thank you for your answer, both seem to select all of the lines containing new o*, including the ones I don't want included.

    – yoranus
    Jan 19 at 12:28











  • grep (GNU grep) 3.0

    – yoranus
    Jan 19 at 12:32











  • Yeah, that is exactly what I want - when I run your awk solution, it gives me no output at all.

    – yoranus
    Jan 19 at 12:37











  • Okay, I tried your grep -zoP 'new o.*?(n|$)(?!y()' solution after deleting reduntant strings that were in the file I wanted to search and it seemed to work.

    – yoranus
    Jan 19 at 12:38











  • Windows 10, no, the file is a bit different, in front of every one of those lines is debug information on when it was executed, example; [01:45:47], I just regex'ed these out and I was able to use your grep solution, thanks a bunch.

    – yoranus
    Jan 19 at 12:42





















0














If perl can also be an option, try this,



perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } '


With your inputs



$ cat yoranus.txt
new o85 = x(-1.3);
y(o85, 12.0, 91.2, 5);
y(o85, 12.0, 91.2, 6);
y(o85, 12.0, 91.2, 7);
new o86 = x(-1.3);
new o87 = x(-1.3);
y(o87, 12.0, 91.2, 9);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o90 = x(-1.3);
y(o90, 12.0, 91.2, 3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o96 = x(-1.3);
y(o96, 12.0, 91.2, 3);
new o97 = x(-1.3);
new o98 = x(-1.3);
new o99 = x(-1.3);
$ perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } ' yoranus.txt
new o86 = x(-1.3);
new o88 = x(-1.3);
new o89 = x(-1.3);
new o91 = x(-1.3);
new o92 = x(-1.3);
new o93 = x(-1.3);
new o94 = x(-1.3);
new o95 = x(-1.3);
new o97 = x(-1.3);
new o98 = x(-1.3);
$





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2fstackoverflow.com%2fquestions%2f54266812%2fmatch-string-but-only-output-lines-below-it-not-the-matched-string-itself%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









    0














    GNU grep:



    grep -zoP 'new o.*?(n|$)(?!y()'


    or this:



    grep -zoP 'new o.*?;(?!ny()'


    GNU awk:



    $ awk -v RS="n*y[^)]*);n*" -F"n" 'NF>1{for(i=1;i<NF;i++) print $i}' file
    new o86 = x(-1.3);
    new o88 = x(-1.3);
    new o89 = x(-1.3);
    new o91 = x(-1.3);
    new o92 = x(-1.3);
    new o93 = x(-1.3);
    new o94 = x(-1.3);
    new o95 = x(-1.3);
    new o97 = x(-1.3);
    new o98 = x(-1.3);


    For windows carriage return (rn) ending files:



    awk -v RS="[rn]*y[^)]*);[rn]*" -F"[rn]+" 'NF>1{for(i=1;i<NF;i++) print $i}'





    share|improve this answer


























    • Hey, thank you for your answer, both seem to select all of the lines containing new o*, including the ones I don't want included.

      – yoranus
      Jan 19 at 12:28











    • grep (GNU grep) 3.0

      – yoranus
      Jan 19 at 12:32











    • Yeah, that is exactly what I want - when I run your awk solution, it gives me no output at all.

      – yoranus
      Jan 19 at 12:37











    • Okay, I tried your grep -zoP 'new o.*?(n|$)(?!y()' solution after deleting reduntant strings that were in the file I wanted to search and it seemed to work.

      – yoranus
      Jan 19 at 12:38











    • Windows 10, no, the file is a bit different, in front of every one of those lines is debug information on when it was executed, example; [01:45:47], I just regex'ed these out and I was able to use your grep solution, thanks a bunch.

      – yoranus
      Jan 19 at 12:42


















    0














    GNU grep:



    grep -zoP 'new o.*?(n|$)(?!y()'


    or this:



    grep -zoP 'new o.*?;(?!ny()'


    GNU awk:



    $ awk -v RS="n*y[^)]*);n*" -F"n" 'NF>1{for(i=1;i<NF;i++) print $i}' file
    new o86 = x(-1.3);
    new o88 = x(-1.3);
    new o89 = x(-1.3);
    new o91 = x(-1.3);
    new o92 = x(-1.3);
    new o93 = x(-1.3);
    new o94 = x(-1.3);
    new o95 = x(-1.3);
    new o97 = x(-1.3);
    new o98 = x(-1.3);


    For windows carriage return (rn) ending files:



    awk -v RS="[rn]*y[^)]*);[rn]*" -F"[rn]+" 'NF>1{for(i=1;i<NF;i++) print $i}'





    share|improve this answer


























    • Hey, thank you for your answer, both seem to select all of the lines containing new o*, including the ones I don't want included.

      – yoranus
      Jan 19 at 12:28











    • grep (GNU grep) 3.0

      – yoranus
      Jan 19 at 12:32











    • Yeah, that is exactly what I want - when I run your awk solution, it gives me no output at all.

      – yoranus
      Jan 19 at 12:37











    • Okay, I tried your grep -zoP 'new o.*?(n|$)(?!y()' solution after deleting reduntant strings that were in the file I wanted to search and it seemed to work.

      – yoranus
      Jan 19 at 12:38











    • Windows 10, no, the file is a bit different, in front of every one of those lines is debug information on when it was executed, example; [01:45:47], I just regex'ed these out and I was able to use your grep solution, thanks a bunch.

      – yoranus
      Jan 19 at 12:42
















    0












    0








    0







    GNU grep:



    grep -zoP 'new o.*?(n|$)(?!y()'


    or this:



    grep -zoP 'new o.*?;(?!ny()'


    GNU awk:



    $ awk -v RS="n*y[^)]*);n*" -F"n" 'NF>1{for(i=1;i<NF;i++) print $i}' file
    new o86 = x(-1.3);
    new o88 = x(-1.3);
    new o89 = x(-1.3);
    new o91 = x(-1.3);
    new o92 = x(-1.3);
    new o93 = x(-1.3);
    new o94 = x(-1.3);
    new o95 = x(-1.3);
    new o97 = x(-1.3);
    new o98 = x(-1.3);


    For windows carriage return (rn) ending files:



    awk -v RS="[rn]*y[^)]*);[rn]*" -F"[rn]+" 'NF>1{for(i=1;i<NF;i++) print $i}'





    share|improve this answer















    GNU grep:



    grep -zoP 'new o.*?(n|$)(?!y()'


    or this:



    grep -zoP 'new o.*?;(?!ny()'


    GNU awk:



    $ awk -v RS="n*y[^)]*);n*" -F"n" 'NF>1{for(i=1;i<NF;i++) print $i}' file
    new o86 = x(-1.3);
    new o88 = x(-1.3);
    new o89 = x(-1.3);
    new o91 = x(-1.3);
    new o92 = x(-1.3);
    new o93 = x(-1.3);
    new o94 = x(-1.3);
    new o95 = x(-1.3);
    new o97 = x(-1.3);
    new o98 = x(-1.3);


    For windows carriage return (rn) ending files:



    awk -v RS="[rn]*y[^)]*);[rn]*" -F"[rn]+" 'NF>1{for(i=1;i<NF;i++) print $i}'






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 19 at 12:46

























    answered Jan 19 at 12:23









    TiwTiw

    2,52821026




    2,52821026













    • Hey, thank you for your answer, both seem to select all of the lines containing new o*, including the ones I don't want included.

      – yoranus
      Jan 19 at 12:28











    • grep (GNU grep) 3.0

      – yoranus
      Jan 19 at 12:32











    • Yeah, that is exactly what I want - when I run your awk solution, it gives me no output at all.

      – yoranus
      Jan 19 at 12:37











    • Okay, I tried your grep -zoP 'new o.*?(n|$)(?!y()' solution after deleting reduntant strings that were in the file I wanted to search and it seemed to work.

      – yoranus
      Jan 19 at 12:38











    • Windows 10, no, the file is a bit different, in front of every one of those lines is debug information on when it was executed, example; [01:45:47], I just regex'ed these out and I was able to use your grep solution, thanks a bunch.

      – yoranus
      Jan 19 at 12:42





















    • Hey, thank you for your answer, both seem to select all of the lines containing new o*, including the ones I don't want included.

      – yoranus
      Jan 19 at 12:28











    • grep (GNU grep) 3.0

      – yoranus
      Jan 19 at 12:32











    • Yeah, that is exactly what I want - when I run your awk solution, it gives me no output at all.

      – yoranus
      Jan 19 at 12:37











    • Okay, I tried your grep -zoP 'new o.*?(n|$)(?!y()' solution after deleting reduntant strings that were in the file I wanted to search and it seemed to work.

      – yoranus
      Jan 19 at 12:38











    • Windows 10, no, the file is a bit different, in front of every one of those lines is debug information on when it was executed, example; [01:45:47], I just regex'ed these out and I was able to use your grep solution, thanks a bunch.

      – yoranus
      Jan 19 at 12:42



















    Hey, thank you for your answer, both seem to select all of the lines containing new o*, including the ones I don't want included.

    – yoranus
    Jan 19 at 12:28





    Hey, thank you for your answer, both seem to select all of the lines containing new o*, including the ones I don't want included.

    – yoranus
    Jan 19 at 12:28













    grep (GNU grep) 3.0

    – yoranus
    Jan 19 at 12:32





    grep (GNU grep) 3.0

    – yoranus
    Jan 19 at 12:32













    Yeah, that is exactly what I want - when I run your awk solution, it gives me no output at all.

    – yoranus
    Jan 19 at 12:37





    Yeah, that is exactly what I want - when I run your awk solution, it gives me no output at all.

    – yoranus
    Jan 19 at 12:37













    Okay, I tried your grep -zoP 'new o.*?(n|$)(?!y()' solution after deleting reduntant strings that were in the file I wanted to search and it seemed to work.

    – yoranus
    Jan 19 at 12:38





    Okay, I tried your grep -zoP 'new o.*?(n|$)(?!y()' solution after deleting reduntant strings that were in the file I wanted to search and it seemed to work.

    – yoranus
    Jan 19 at 12:38













    Windows 10, no, the file is a bit different, in front of every one of those lines is debug information on when it was executed, example; [01:45:47], I just regex'ed these out and I was able to use your grep solution, thanks a bunch.

    – yoranus
    Jan 19 at 12:42







    Windows 10, no, the file is a bit different, in front of every one of those lines is debug information on when it was executed, example; [01:45:47], I just regex'ed these out and I was able to use your grep solution, thanks a bunch.

    – yoranus
    Jan 19 at 12:42















    0














    If perl can also be an option, try this,



    perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } '


    With your inputs



    $ cat yoranus.txt
    new o85 = x(-1.3);
    y(o85, 12.0, 91.2, 5);
    y(o85, 12.0, 91.2, 6);
    y(o85, 12.0, 91.2, 7);
    new o86 = x(-1.3);
    new o87 = x(-1.3);
    y(o87, 12.0, 91.2, 9);
    new o88 = x(-1.3);
    new o89 = x(-1.3);
    new o90 = x(-1.3);
    y(o90, 12.0, 91.2, 3);
    new o91 = x(-1.3);
    new o92 = x(-1.3);
    new o93 = x(-1.3);
    new o94 = x(-1.3);
    new o95 = x(-1.3);
    new o96 = x(-1.3);
    y(o96, 12.0, 91.2, 3);
    new o97 = x(-1.3);
    new o98 = x(-1.3);
    new o99 = x(-1.3);
    $ perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } ' yoranus.txt
    new o86 = x(-1.3);
    new o88 = x(-1.3);
    new o89 = x(-1.3);
    new o91 = x(-1.3);
    new o92 = x(-1.3);
    new o93 = x(-1.3);
    new o94 = x(-1.3);
    new o95 = x(-1.3);
    new o97 = x(-1.3);
    new o98 = x(-1.3);
    $





    share|improve this answer




























      0














      If perl can also be an option, try this,



      perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } '


      With your inputs



      $ cat yoranus.txt
      new o85 = x(-1.3);
      y(o85, 12.0, 91.2, 5);
      y(o85, 12.0, 91.2, 6);
      y(o85, 12.0, 91.2, 7);
      new o86 = x(-1.3);
      new o87 = x(-1.3);
      y(o87, 12.0, 91.2, 9);
      new o88 = x(-1.3);
      new o89 = x(-1.3);
      new o90 = x(-1.3);
      y(o90, 12.0, 91.2, 3);
      new o91 = x(-1.3);
      new o92 = x(-1.3);
      new o93 = x(-1.3);
      new o94 = x(-1.3);
      new o95 = x(-1.3);
      new o96 = x(-1.3);
      y(o96, 12.0, 91.2, 3);
      new o97 = x(-1.3);
      new o98 = x(-1.3);
      new o99 = x(-1.3);
      $ perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } ' yoranus.txt
      new o86 = x(-1.3);
      new o88 = x(-1.3);
      new o89 = x(-1.3);
      new o91 = x(-1.3);
      new o92 = x(-1.3);
      new o93 = x(-1.3);
      new o94 = x(-1.3);
      new o95 = x(-1.3);
      new o97 = x(-1.3);
      new o98 = x(-1.3);
      $





      share|improve this answer


























        0












        0








        0







        If perl can also be an option, try this,



        perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } '


        With your inputs



        $ cat yoranus.txt
        new o85 = x(-1.3);
        y(o85, 12.0, 91.2, 5);
        y(o85, 12.0, 91.2, 6);
        y(o85, 12.0, 91.2, 7);
        new o86 = x(-1.3);
        new o87 = x(-1.3);
        y(o87, 12.0, 91.2, 9);
        new o88 = x(-1.3);
        new o89 = x(-1.3);
        new o90 = x(-1.3);
        y(o90, 12.0, 91.2, 3);
        new o91 = x(-1.3);
        new o92 = x(-1.3);
        new o93 = x(-1.3);
        new o94 = x(-1.3);
        new o95 = x(-1.3);
        new o96 = x(-1.3);
        y(o96, 12.0, 91.2, 3);
        new o97 = x(-1.3);
        new o98 = x(-1.3);
        new o99 = x(-1.3);
        $ perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } ' yoranus.txt
        new o86 = x(-1.3);
        new o88 = x(-1.3);
        new o89 = x(-1.3);
        new o91 = x(-1.3);
        new o92 = x(-1.3);
        new o93 = x(-1.3);
        new o94 = x(-1.3);
        new o95 = x(-1.3);
        new o97 = x(-1.3);
        new o98 = x(-1.3);
        $





        share|improve this answer













        If perl can also be an option, try this,



        perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } '


        With your inputs



        $ cat yoranus.txt
        new o85 = x(-1.3);
        y(o85, 12.0, 91.2, 5);
        y(o85, 12.0, 91.2, 6);
        y(o85, 12.0, 91.2, 7);
        new o86 = x(-1.3);
        new o87 = x(-1.3);
        y(o87, 12.0, 91.2, 9);
        new o88 = x(-1.3);
        new o89 = x(-1.3);
        new o90 = x(-1.3);
        y(o90, 12.0, 91.2, 3);
        new o91 = x(-1.3);
        new o92 = x(-1.3);
        new o93 = x(-1.3);
        new o94 = x(-1.3);
        new o95 = x(-1.3);
        new o96 = x(-1.3);
        y(o96, 12.0, 91.2, 3);
        new o97 = x(-1.3);
        new o98 = x(-1.3);
        new o99 = x(-1.3);
        $ perl -0777 -ne ' while ( /y(.+?n(?<!=y)((?-s:^new.+?n)+)(?<!=y)(new.+?n)(?=y(|Z)/mgs ) { print "$1" } ' yoranus.txt
        new o86 = x(-1.3);
        new o88 = x(-1.3);
        new o89 = x(-1.3);
        new o91 = x(-1.3);
        new o92 = x(-1.3);
        new o93 = x(-1.3);
        new o94 = x(-1.3);
        new o95 = x(-1.3);
        new o97 = x(-1.3);
        new o98 = x(-1.3);
        $






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 21 at 12:14









        stack0114106stack0114106

        3,1702417




        3,1702417






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • 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%2fstackoverflow.com%2fquestions%2f54266812%2fmatch-string-but-only-output-lines-below-it-not-the-matched-string-itself%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

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage