• Login
Community
  • Login

Delete every line below a bookmarked line.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
47 Posts 6 Posters 2.4k 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.
  • A
    Antheds Kennel
    last edited by Antheds Kennel Dec 30, 2024, 5:57 PM Dec 30, 2024, 5:52 PM

    @guy038 said in Delete every line below a bookmarked line.:

    $1

    Hello again, I have uploaded a picture showing before and after with the code you gave first.
    https://ibb.co/W51vDPT

    P 2 Replies Last reply Dec 30, 2024, 7:00 PM Reply Quote 0
    • G
      guy038
      last edited by guy038 Dec 30, 2024, 6:28 PM Dec 30, 2024, 6:15 PM

      Hello, @antheds-kennel ,

      Globally, my regex S/R simply keep all the odd lines et delete all the even lines !

      But, looking at your picture, I’m wondering :

      May be, you want to delete the lines 2, 6 and 10, only ? So, each line which is right after a bookmarked line, throughout the end of file ?

      BR

      guy038

      A 1 Reply Last reply Dec 31, 2024, 10:02 AM Reply Quote 0
      • P
        PeterJones @Antheds Kennel
        last edited by Dec 30, 2024, 7:00 PM

        @Antheds-Kennel said in Delete every line below a bookmarked line.:

        Hello again, I have uploaded a picture showing before and after with the code you gave first

        You can just paste pictures into your reply, so they are embedded without people having to click a link to an external site.

        And with some external sites, you can use the ![](...) syntax to embed the external image itself, rather than linking to their advertisement-ridden landing page
        Using the code ![](https://i.ibb.co/zxwV87k/33.jpg) will embed your external image:

        But since external sites can change their rules (thousands of imgur-hosted external images will no longer show in the forum, even though they used to work here, so much of our discussion history now has broken images because of the external site outside of our control), so it’s really best to just paste your image directly in your post.

        A 1 Reply Last reply Dec 31, 2024, 10:06 AM Reply Quote 1
        • D
          dr ramaanand @dr ramaanand
          last edited by dr ramaanand Dec 30, 2024, 7:07 PM Dec 30, 2024, 7:05 PM

          @dr-ramaanand said in Delete every line below a bookmarked line.:

          #STNEW:_TEST-\d+\R\K(?:..)

          @Antheds-Kennel The above Regular expression will help find it. Type #STNEW:_TEST-\d+\R\K(?:.*.*) in the Find field and then leave the Replace field blank, tick/select the Regular expression mode and hit Replace All or Replace in files if you want to do this in multiple files to get rid of it (that will get rid of only one line, just below the line beginning with #STNEW:_TEST-)

          1 Reply Last reply Reply Quote 0
          • P
            PeterJones @Antheds Kennel
            last edited by PeterJones Dec 30, 2024, 9:03 PM Dec 30, 2024, 7:08 PM

            @Antheds-Kennel ,

            After looking at your image, it is showing that the regex deletes all the lines after #STNEW: lines, and it seems you might be trying to say “but I only wanted it to delete the ones after a bookmark, so lines 2, 6, and 10 only, without also deleting 4, 8, 12, and 14”? Because if so, that is something you cannot do only with regex, because the regex engine cannot see your bookmarks. You CANNOT bookmark lines 1, 5, and 9, and then say “delete the lines right after a bookmark”.

            The easiest thing to do would be to bookmark the lines you actually want to delete, rather than the line before the one you want to delete, and then use Search > Bookmark > Remove Bookmarked Lines. Or, simpler, if you’re using the Mark dialog to bookmark the lines to begin with (as you show in your screenshot), then just do a search/replace regex to do the search-and-delete in one step: Something like FIND = #STNEW:_TEST-(1|3|5)\R(.*\R) REPLACE = $2

            –
            Update: that was the wrong results; FIND = (#STNEW:_TEST-(?:1|3|5)\R)(.*\R) REPLACE = $1 is, I think, what I meant (untested, as I away from NPP)

            A 1 Reply Last reply Dec 31, 2024, 10:10 AM Reply Quote 0
            • G
              guy038
              last edited by guy038 Dec 30, 2024, 8:46 PM Dec 30, 2024, 8:45 PM

              Hi, @antheds-kennel, @datatraveller1, @dr-ramaanand, @peterjones and All,

              Peter, you said :

              … Because if so, that is something you cannot do only with regex, because the regex engine cannot see your bookmarks. You CANNOT bookmark lines 1, 5, and 9, and then say “delete the lines right after a bookmark”.

              I agree with this statement ! Regexes and bookmarks are different features ! However, as the OP bookmarked the lines ending with digits 1|3|5, we can imagine this regex S/R :

              FIND ([135]\R).+\R

              REPLACE $1

              As expected, it would delete the lines 2, 6 and 10, only, leaving all the other lines unchanged !

              Best Regards

              guy038

              1 Reply Last reply Reply Quote 0
              • D
                dr ramaanand @dr ramaanand
                last edited by dr ramaanand Dec 31, 2024, 3:06 AM Dec 31, 2024, 2:54 AM

                Yes, that works, unless thr OP wants to delete other lines or skip deleting other lines. See https://regex101.com/r/EjNI9Y/1

                1 Reply Last reply Reply Quote 0
                • G
                  guy038
                  last edited by Dec 31, 2024, 9:39 AM

                  Hi, @peterjones and All,

                  Sorry, Peter,I should have read your post thoroughly, as you already provided a similar solution to mine : FIND (#STNEW:_TEST-(?:1|3|5)\R)(.*\R) and REPLACE = $1

                  BR

                  guy038

                  1 Reply Last reply Reply Quote 0
                  • A
                    Antheds Kennel @guy038
                    last edited by Antheds Kennel Dec 31, 2024, 10:05 AM Dec 31, 2024, 10:02 AM

                    @guy038 Hello and goodmorning from Sweden, I reached out to Ai this morning to see if it could help you understand what I mean. And I got this answer: "Delete Only the Lines Below Bookmarked Lines
                    Step 1: Bookmark the Correct Lines
                    Ensure you’ve bookmarked only the lines directly above the lines you want to delete. Use Ctrl+F2 to toggle bookmarks on or off for the relevant lines.
                    Step 2: Verify Bookmarks
                    Go to Search → Bookmarks → Show All Bookmarks to confirm that only the correct lines are bookmarked.
                    Follow these steps precisely:

                    Go to Macro → Start Recording.
                    Perform these actions in sequence:
                    Press Ctrl+F2 to jump to the next bookmark.
                    Press the Down Arrow key to move the cursor to the line below.
                    Press Ctrl+L to delete the line below.
                    Press Ctrl+F2 again to jump to the next bookmark.
                    Stop the recording via Macro → Stop Recording.
                    Save the macro via Macro → Save Current Recorded Macro.
                    Step 4: Run the Macro Until All Bookmarks Are Processed
                    Go to Macro → Run a Macro Multiple Times.
                    Select Run until the end of the file to ensure all lines below the bookmarked lines are deleted.
                    If This Still Doesn’t Work
                    If the macro doesn’t behave as expected, we could use a manual method involving regex. Bookmarks in Notepad++ can’t be directly accessed by regex, but they can act as visual markers while you use regex for other patterns.

                    Deleting lines below bookmarked lines in Notepad++ cannot do by regex: Alternative alternate outlines flex recommendations use text off regular ACL–"

                    Sorry for all the mistakes I make. I accept all the tips and corrections you give me. So I do what I can to correct my posts so that they don’t become wrong again. Kind regards Thore

                    1 Reply Last reply Reply Quote 0
                    • A
                      Antheds Kennel @PeterJones
                      last edited by Dec 31, 2024, 10:06 AM

                      @PeterJones said in Delete every line below a bookmarked line.:

                      @Antheds-Kennel said in Delete every line below a bookmarked line.:

                      Hello again, I have uploaded a picture showing before and after with the code you gave first

                      You can just paste pictures into your reply, so they are embedded without people having to click a link to an external site.

                      And with some external sites, you can use the ![](...) syntax to embed the external image itself, rather than linking to their advertisement-ridden landing page
                      Using the code ![](https://i.ibb.co/zxwV87k/33.jpg) will embed your external image:

                      But since external sites can change their rules (thousands of imgur-hosted external images will no longer show in the forum, even though they used to work here, so much of our discussion history now has broken images because of the external site outside of our control), so it’s really best to just paste your image directly in your post.

                      Ok, i will do that next time, or should i correct that one i already have posted?

                      1 Reply Last reply Reply Quote 0
                      • A
                        Antheds Kennel @PeterJones
                        last edited by Dec 31, 2024, 10:10 AM

                        @PeterJones It’s true that I only want to delete the lines below the ones that are bookmarked. So technically I could blureed out the “#STNEW” lines since my original question was to delete all lines below the ones that are bookmarked. So I admit I was unclear.

                        1 Reply Last reply Reply Quote 0
                        • G
                          guy038
                          last edited by guy038 Dec 31, 2024, 5:28 PM Dec 31, 2024, 1:20 PM

                          Hi, @antheds-kennel, @datatraveller1, @dr-ramaanand, @peterjones and All,

                          Sorry, @antheds-kennel, But I still do not understand your goal ! You said :

                          I only want to delete the lines below the ones that are bookmarked.

                          Do you mean :

                          I only want to delete each SINGLE line which is below the bookmarked lines

                          or

                          I only want to delete all the lines which are below the bookmarked lines


                          In addition, in the description of your macro, you said, twice :

                          Press Ctrl+F2 to jump to the next bookmark.

                          This is not right ! This feature does not enable you to move to the next bookmark ! The Ctrl + F2 feature TOGGLE the Bookmark status of the current line :

                          • If the current line is not bookmarked, a Ctrl + F2 action will bookmark this line

                          • If the current line is bookmarked, a Ctrl + F2 action will un-bookmark this line


                          To move to a bookmark, you can, either :

                          • Hit the F2 key, which moves to the next bookmark

                          • Hit the Shift + F2 combination, which moves to the previous bookmark

                          BR

                          guy038

                          A 3 Replies Last reply Jan 1, 2025, 11:38 AM Reply Quote 0
                          • A
                            Antheds Kennel @guy038
                            last edited by Jan 1, 2025, 11:38 AM

                            @guy038 said in Delete every line below a bookmarked line.:

                            I only want to delete all the lines which are below the bookmarked lines

                            That is what i want, Sorry for not being clear enough, english is not my first language, but i will do my best.

                            1 Reply Last reply Reply Quote 0
                            • A
                              Antheds Kennel @guy038
                              last edited by Jan 1, 2025, 11:53 AM

                              @guy038 Hello and happy new year, what I attached last time was a suggestion from ChatGPT. What I do is:

                              1. Bookmark all the lines that I want to delete (after I delete the line below).
                              2. Record a macro where I click F2->down arrow.
                              3. CTRL+L to delete that line.
                              4. Stop recording.
                              5. Click Macro->Run A Macro Multiply Times->Run Until…(with the macro I just created).
                              6. Now I’m supposed to go via Search->Bookmark->Remove Bookmarked Lines, but I can’t get that far because the macro deletes more than what I want to delete.
                              1 Reply Last reply Reply Quote 0
                              • G
                                guy038
                                last edited by guy038 Jan 1, 2025, 12:47 PM Jan 1, 2025, 12:34 PM

                                Hi, @antheds-kennel, @datatraveller1, @dr-ramaanand, @peterjones and All,

                                @antheds-kennel, you said :

                                I want to delete all the lines which are below the bookmarked lines

                                OK ! Then, if I consider this INPUT text, in a new tab :

                                  Line 01
                                  Line 02
                                  Line 03
                                • Line 04
                                  Line 05
                                  Line 06
                                • Line 07
                                  Line 08
                                  Line 09
                                  Line 10
                                  Line 11
                                • Line 12
                                  Line 13
                                  Line 14
                                  Line 15
                                  Line 16
                                  Line 17
                                  Line 18
                                  Line 19
                                  Line 20
                                  Line 21
                                  Line 22
                                

                                Where only the lines 4, 7 and 12 are bookmarked

                                You’re expecting this OUTPUT text, aren’t you ?

                                  Line 01
                                  Line 02
                                  Line 03
                                • Line 04
                                • Line 07
                                • Line 12
                                

                                If this behavior is the one you looking for :

                                • Firstly, bookmark all the unmarked lines which lay before the first bookmarked line of current file ( so the lines 01, 02 and 03 in our example )

                                • Secondly, do a mouse right-click, within the bookmark margin, on the left, and run the Remove Non-Bookmarked Lines option

                                BR

                                guy038

                                A 1 Reply Last reply Jan 1, 2025, 1:11 PM Reply Quote 0
                                • A
                                  Alan Kilborn @guy038
                                  last edited by Alan Kilborn Jan 1, 2025, 3:55 PM Jan 1, 2025, 1:11 PM

                                  @guy038 said :

                                  …bookmark all the unmarked lines which lay before the first bookmarked line

                                  This may be a lot of manual effort if there are many lines upon which to place a bookmark – think about clicking the margin or pressing F2 hundreds of times. :-(

                                  Making a text selection of all of these lines and then choosing the Toggle Bookmark command does not do it; it sets a bookmark on the (single) line of the caret in the selection.

                                  Here’s a way to automate placing bookmarks on multiple lines, acting on @guy038 's example text:

                                  • put a character that does not appear in the document at the end of the last line upon which bookmarking of all individual lines is desired:
                                    c00a17d5-7895-41d8-9703-5067f6b9fd7d-image.png
                                  • run this marking operation:
                                    b8f93f73-44a1-46c5-82f3-c4f3c51f388c-image.png
                                  • obtain this result:
                                    520d4b7c-b975-424c-b75e-62932cfb3302-image.png
                                  • remove the extra character added earlier
                                  1 Reply Last reply Reply Quote 2
                                  • G
                                    guy038
                                    last edited by Jan 1, 2025, 1:48 PM

                                    Hello, @alan-kilborn and All,

                                    Alan, nice catch ;-))

                                    Happy New Year !

                                    guy038

                                    1 Reply Last reply Reply Quote 1
                                    • G
                                      guy038
                                      last edited by Jan 1, 2025, 5:33 PM

                                      Hello, @alan-kilborn and All,

                                      BTW, I’m thinking : would it be a problem if :

                                      • When no standard selection, in current file, the commands Toggle Bookmark, Clear All Bookmarks, Cut Bookmarked Lines, Copy Bookmarked Lines , Paste to (Replace) Boomarked lines, Remove Bookmarked lines, Remove Non-Bookmarked Lines and Inverse Bookmark would act on the entire file

                                      • When a standard selection would occur ( even partially ), these eight commands would act on that selection only


                                      • Could this new behavior be extended to multiple standard selections ?

                                      • More important : what about a Ctrl + Z / Ctrl + Y action ?

                                      Best Regards,

                                      guy038

                                      A 1 Reply Last reply Jan 1, 2025, 5:36 PM Reply Quote 0
                                      • A
                                        Alan Kilborn @guy038
                                        last edited by Alan Kilborn Jan 1, 2025, 5:44 PM Jan 1, 2025, 5:36 PM

                                        @guy038 said :

                                        When no standard selection, in current file, the commands Toggle Bookmark, Clear All Bookmarks, Cut Bookmarked Lines, Copy Bookmarked Lines , Paste to (Replace) Boomarked lines, Remove Bookmarked lines, Remove Non-Bookmarked Lines and Inverse Bookmark would act on the entire file

                                        With the exception of Toggle Bookmark, these commands already all work on the entire file.

                                        When a standard selection would occur ( even partially ), these eight commands would act on that selection only

                                        You should start with a “feature request” for this behavior.

                                        Could this new behavior be extended to multiple standard selections ?

                                        I would think that only a single stream-type selection should be supported. Anything more than that overcomplicates a feature request (and probably kills it).


                                        what about a Ctrl + Z / Ctrl + Y action ?

                                        Not applicable.
                                        Undo/redo applies to textual changes only.

                                        A 1 Reply Last reply Jan 1, 2025, 7:48 PM Reply Quote 2
                                        • A
                                          Alan Kilborn @Alan Kilborn
                                          last edited by Jan 1, 2025, 7:48 PM

                                          You should start with a “feature request” for this behavior.

                                          And HERE it is.

                                          D 1 Reply Last reply Jan 2, 2025, 9:46 AM Reply Quote 1
                                          23 out of 47
                                          • First post
                                            23/47
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors