• Login
Community
  • Login

How to find text, then delete the next line?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 3 Posters 2.0k 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.
  • S
    Scott DuBose
    last edited by Nov 3, 2019, 5:31 PM

    How can I find text, then delete the next line? I know how to find the text, but how do I tell N++ to then delete the line following?
    Or… find text, bookmark the line following?
    Thanks…

    1 Reply Last reply Reply Quote 0
    • T
      Terry R
      last edited by Nov 3, 2019, 10:41 PM

      @Scott-DuBose said in How to find text, then delete the next line?:

      How can I find text, then delete the next line?

      You haven’t explained if you are finding text through a regular expression (regex) or just by searching for that exact text or manually.

      The easiest method of removing a following line is through a regex. It will allow you to search using a search pattern, then remove the folowing line. Example is

      line here
      line here
      this line is what i want to find
      this line I want to delete
      

      Regex used would be similar to (using the Replace function):
      Find What:^.*i want to find\R\K^.*\R
      Replace with:empty field here

      So the regex uses the first portion to find a line ending in “i want to find” followed by a carriage return/line feed. It then promptly discards that selection (using the \K) and then selects the complete line following and replaces it with nothing, so deleting it. If the following line is empty it will still work.

      Terry

      S 1 Reply Last reply Nov 4, 2019, 10:38 AM Reply Quote 3
      • S
        Scott DuBose
        last edited by Nov 4, 2019, 3:23 AM

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • S
          Scott DuBose
          last edited by Nov 4, 2019, 4:01 AM

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • S
            Scott DuBose @Terry R
            last edited by Nov 4, 2019, 10:38 AM

            Thanks, it worked! Example:

            Message 34159
            34158
            2009-01-02 09:40:51

            I Find: Message.?\R\K^.\r

            Which then selects 34158 on the second line.

            When I enter nothing in the “Replace with” field, and clicked " Replace" - it did nothing. But when I clicked “Replace All,” it cleaned all the lines I wanted gone. Thanks for your help…

            S 1 Reply Last reply Nov 4, 2019, 10:58 AM Reply Quote 0
            • S
              Scott DuBose @Scott DuBose
              last edited by Nov 4, 2019, 10:58 AM

              Why are asterisks being removed from my post? Regex used isalt text

              A 1 Reply Last reply Nov 4, 2019, 1:17 PM Reply Quote 0
              • A
                Alan Kilborn @Scott DuBose
                last edited by Nov 4, 2019, 1:17 PM

                @Scott-DuBose said in How to find text, then delete the next line?:

                Why are asterisks being removed from my post?

                Because this forum uses a form of “markdown” and the asterisk is a character that has special meaning. It adds italics if you wrap a word with 2 asterisks.

                The way to get it to NOT interfere with your text is to use backticks around your text; then what you type will appear like this and will not be messed with.

                1 Reply Last reply Reply Quote 1
                • S
                  Scott DuBose
                  last edited by Nov 4, 2019, 7:59 PM

                  Thanks, had to look up backtick… :-) Found it!

                  1 Reply Last reply Reply Quote 2
                  • S
                    Scott DuBose
                    last edited by Nov 5, 2019, 1:20 AM

                    Thanks, in a document with 124,000 lines, this deleted 20,000 lines in about 10 seconds. Notepad++ is so awesome. Shoutout to Don Ho

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