Search for a text and copy the next lines of codes



  • Hi all,

    Is there any way where I search for a text and copy the next lines of codes?

    Sample text:
    Line1Texttosearch SEARCHME
    Line2someTextHere
    Line3someTextHere
    Line4copyThisLine IWANTTOCOPYTHISLINE0001
    Line5Texttosearch SEARCHME
    Line6someTextHere
    Line7someTextHere
    Line8copyThisLine IWANTTOCOPYTHISLINE0002

    In here I have to find the keyword “SEARCHME”, it will give multiple results which is the Line1 and Line5. What I want to copy is the contents of the next two lines for each keyword which Line4 and Line8. The result of what I copy to clipboard would be the Line4 and Line8 only.

    Result:
    Line4copyThisLine IWANTTOCOPYTHISLINE0001
    Line8copyThisLine IWANTTOCOPYTHISLINE0002

    I don’t mind copying the Line3, Line4, Line6 and Line7 if it makes it easier.

    Kind Regards,
    Kev



  • You can (after locating them) select Line4, hold down Ctrl, and select Line8. Holding Ctrl, you can select many lines, with spaces between.
    Capture.PNG
    Hope I helped!



  • @Lucca-Peluca

    The advice you offered is not good for what I suspect @Kev-Alejandrino wants.



  • @Kev-Alejandrino

    Thanks for the fairly decent problem description!

    For a possible solution:

    Try a “marking” operation; start by pressing Ctrl+m and then filling out the Mark tab this way:

    79e37664-511b-4654-889f-255ad96b64b9-image.png

    Here’s the text for the Find what box for convenient copy/paste use: (?-s)SEARCHME(?:.*\R){3}\K.*

    After you press the Mark All button, you should see the text you want highlighted in red like I show.

    At that point it is a simple matter of pressing the Copy Marked Text button.



  • @Alan-Kilborn said in Search for a text and copy the next lines of codes:

    (?-s)SEARCHME(?:.\R){3}\K.

    Thank you! It works just what I wanted.


Log in to reply