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
    Line4copyThisLine IWANTTOCOPYTHISLINE0001
    Line5Texttosearch SEARCHME
    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.

    Line4copyThisLine IWANTTOCOPYTHISLINE0001
    Line8copyThisLine IWANTTOCOPYTHISLINE0002

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

    Kind Regards,

  • You can (after locating them) select Line4, hold down Ctrl, and select Line8. Holding Ctrl, you can select many lines, with spaces between.
    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:


    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:


    Thank you! It works just what I wanted.

Log in to reply