• Login
Community
  • Login

Search for a text and copy the next lines of codes

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 375 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K
    Kev Alejandrino
    last edited by Jun 18, 2021, 8:15 AM

    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

    A 1 Reply Last reply Jun 18, 2021, 12:07 PM Reply Quote 2
    • L
      Lucca Peluca
      last edited by Lucca Peluca Jun 18, 2021, 9:24 AM Jun 18, 2021, 9:22 AM

      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!

      A 1 Reply Last reply Jun 18, 2021, 12:04 PM Reply Quote 0
      • A
        Alan Kilborn @Lucca Peluca
        last edited by Jun 18, 2021, 12:04 PM

        @Lucca-Peluca

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

        1 Reply Last reply Reply Quote 1
        • A
          Alan Kilborn @Kev Alejandrino
          last edited by Jun 18, 2021, 12:07 PM

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

          1 Reply Last reply Reply Quote 3
          • K
            Kev Alejandrino
            last edited by Jun 21, 2021, 12:05 PM

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

            1 Reply Last reply Reply Quote 2
            5 out of 5
            • First post
              5/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors