Community
    • Login

    delete line between bookmark

    Scheduled Pinned Locked Moved General Discussion
    45 Posts 4 Posters 14.1k 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.
    • pinuzzu99P
      pinuzzu99
      last edited by

      or also, i have more txt like this:

      jasortrtn25hoon@hotmail.com:bartrall2335
      2017-07-08 12.35.03_5.jpg                         			32KB			             08/07/2017 19:34:57
      2017-07-08 12.35.03_8.jpg                         			71KB			             08/07/2017 19:34:57
      2017-07-08 12.35.10_4.jpg                         			70KB			             08/07/2017 19:35:04
      2017-07-08 12.35.10_5.jpg                         			46KB			             08/07/2017 19:35:04
      2017-07-08 12.35.10_10.jpg                        			47KB			             08/07/2017 19:35:04
      2017-07-08 12.35.10_45.jpg                        			99KB			             08/07/2017 19:35:08
      2017-07-08 12.35.47_31.jpg                        			2116KB			           08/07/2017 19:35:27
      2017-07-08 12.46.13_4.jpg                         			34KB			             08/07/2017 19:45:21
      2017-07-08 12.46.13_12.jpg                        			48KB			             08/07/2017 19:45:37
      2017-07-08 12.46.13_13.jpg                        			97KB			             08/07/2017 19:45:37
      2017-07-08 12.46.13_17.jpg                        			28KB			             08/07/2017 19:45:38
      2017-07-08 12.46.13_20.jpg                        			3957KB			           08/07/2017 19:45:39
      2017-07-08 12.46.13_21.jpg                        			3956KB			           08/07/2017 19:45:39
      2017-07-08 12.46.13_22.jpg                        			42KB			             08/07/2017 19:45:40
      2017-07-08 12.47.08_47.jpg                        			53KB			             08/07/2017 19:46:39
      2017-07-08 12.48.43_11.jpg                        			3932KB			           08/07/2017 19:48:39
      2017-07-08 12.48.43_12.jpg                        			59KB			             08/07/2017 19:48:40
      2017-07-08 12.48.43_15.jpg                        			84KB			             08/07/2017 19:48:41
      2017-07-22 17.09.12.png                           			2008KB			           23/07/2017 00:09:12
      2017-07-25 10.49.47.jpg                           			592KB			            25/07/2017 17:49:47
      2017-07-26 20.15.16.jpg                           			7532KB			           27/07/2017 03:15:18
      2017-07-30 18.50.30.jpg                           			7564KB		
      and other may line
      and other may line
      2017-07-25 01.22.59.jpg                           			102KB			            25/07/2017 08:22:59
      
      ============================================
      skysfsfff@gmail.cam:ksddsfdsfy37   
      

      i want delete all line between 2 mail like this:

      jasortrtn25hoon@hotmail.com:bartrall2335
      skysfsfff@gmail.cam:ksddsfdsfy37 
      

      how to? apart begin/end select…
      have another method or regex?

      Alan KilbornA 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @pinuzzu99
        last edited by

        @pinuzzu99 said in delete line between bookmark:

        Is it possible to delete lines between 2 bookmarks?

        There is no direct command to do so.

        if not, as i believe, i hope this feature is implemented in future versions of np++

        This would be a tough thing to implement, logically. For example, how would it work? You could have many bookmarks; how would Notepad++ know which 2 you wanted to delete all the text between? Also, assuming the previous could be determined, would you include or exclude the (starting and/or ending) bookmarked lines?

        1 Reply Last reply Reply Quote 1
        • Alan KilbornA
          Alan Kilborn @pinuzzu99
          last edited by

          @pinuzzu99 said in delete line between bookmark:

          i want delete all line between 2 mail like this:

          It sure seems like you have been been provided enough regex examples along these lines previously to be able to solve this one yourself. Try to keep in mind that this is a community for discussing Notepad++ topics, not and endless discussion of how to work with regular expressions.

          1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @pinuzzu99
            last edited by

            @pinuzzu99 said in delete line between bookmark:

            how to? apart begin/end select…

            If you asking, how can you manually select a LOT of text without having to hold shift+(caret motion key) or click+drag with the mouse, well, there is a way. The Edit menu has a Begin / End Select command. Navigate to where you want to start your select, execute that command once. Now, navigate to where you want to end your selection, perhaps via a search (because remember your ending text is FAR AWAY from your starting point), and then execute the Begin / End Select command a second time. When you do that, all text between your remembered starting point and the current caret position will become selected, for copying/deleting/moving/whatever.

            1 Reply Last reply Reply Quote 2
            • pinuzzu99P
              pinuzzu99
              last edited by

              i know Begin/End Select…
              i search an alternative way…
              and bookmark, as has the function delete lines, I’d like to have a function that eliminates lines within a certain range.
              precisely if I only had 2 bookmarks I would like to be able to eliminate this range.
              I found a regex that eliminates a predefined range of lines (10-100-xxxx) but that’s not what I’m looking for, because my ranges vary in number.

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • guy038G
                guy038
                last edited by

                Hello, @pinuzzu99, @alan-kilborn All,

                Based on the regexes given in the post, below :

                https://community.notepad-plus-plus.org/post/50272

                I think that the similar regex S/R, below, should do the job !

                SEARCH (?-s)^(?!.+@).*\R?

                REPLACE Leave EMPTY

                Notes :

                • The first part (?-s) is an in-line modifier, which means that any regex dot symbol ( . ) matches a single standard character

                • Then the (?!.+@) is a negative look-ahead structure , which means that , from beginning of line, any non-null range of chars till a @ symbol must not exist.

                • If it’s the case ( So, a line without an e-mail address ! ) the final part .*\R? matches any range, even null, of chars, from beginning of line, followed with its possible line-break

                • As the replacement field is empty, any line, not containing a @ symbol, is then deleted !


                However, @pinuzzu99, it would be good if you follow Alan’s advice and try to learn, at least, the basics of regular expressions!

                No doubt, you will make big mistakes at first, but little by little, you will understand their syntax and find a particular regular expression for each specific problem. Believe me, after a certain point, you won’t go back ;-))

                Best Regards,

                guy038

                1 Reply Last reply Reply Quote 2
                • Alan KilbornA
                  Alan Kilborn @pinuzzu99
                  last edited by Alan Kilborn

                  @pinuzzu99 said in delete line between bookmark:

                  I’d like to have a function that eliminates lines within a certain range.

                  If you’re willing to use the Pythonscript plugin, here is a script that will do such a thing:

                  # -*- coding: utf-8 -*-
                  
                  from Npp import editor, notepad
                  
                  def main():
                  
                      user_input = ''
                      while True:
                          user_input = notepad.prompt('Enter first line # of range to delete:', '', user_input)
                          if user_input == None: return  # user pressed Cancel
                          try:
                              if user_input.lower() == 'bof': user_input = 1
                              elif user_input.lower() == 'eof': user_input = editor.getLineCount()
                              line1 = int(user_input)
                              if not (1 <= line1 <= editor.getLineCount()): raise ValueError
                          except ValueError:
                              continue
                          break
                      user_input = ''
                      while True:
                          user_input = notepad.prompt('Enter last line # of range to delete:', '', user_input)
                          if user_input == None: return  # user pressed Cancel
                          try:
                              if user_input.lower() == 'bof': user_input = 1
                              elif user_input.lower() == 'eof': user_input = editor.getLineCount()
                              line2 = int(user_input)
                              if not (1 <= line2 <= editor.getLineCount()): raise ValueError
                          except ValueError:
                              continue
                          break
                      line1 -= 1; line2 -= 1  # convert "user" line numbers to "system" line numbers
                      if line1 > line2: (line1, line2) = (line2, line1)
                      start_pos = editor.positionFromLine(line1)
                      end_pos = editor.positionFromLine(line2) + len(editor.getLine(line2))
                      editor.beginUndoAction()
                      editor.deleteRange(start_pos, end_pos - start_pos)
                      editor.endUndoAction()
                  
                  main()
                  
                  

                  In addition to using integer line numbers at the prompts, you can also use BOF for beginning-of-file and/or EOF for end-of-file.

                  1 Reply Last reply Reply Quote 1
                  • pinuzzu99P
                    pinuzzu99
                    last edited by

                    @guy038 tanxs for your reply, always highly appreciated!
                    but your string with replace, delete only one line at time; with replace all delete all line.
                    this is another specific case, similar but different from the post you indicated above…
                    here I want to delete only a range of lines, between 2 emails, but only that, not all lines on my txt. I need to see what they contain first, then delete that range, but only that, not all on only one shot.
                    I need a function like Begin/End Select, but with this function to put an End to the selection I have to scroll all the lines to the bottom, and sometimes I have intervals of even 10,000 lines…
                    so I need a command that, given the first few lines, if I consider it ok, I want to delete them all but only until the next email. I need a command to delete lines INCLUDED in 2 emails. only those, not all.

                    @ Alan
                    tanxs also for your suggestion. now i try it.

                    1 Reply Last reply Reply Quote 1
                    • pinuzzu99P
                      pinuzzu99
                      last edited by pinuzzu99

                      Alan, please, explain me how to work.
                      installed python plugin, copy your script and saved into plug folder on python, i don’t understand ho to insert range into script.
                      see my shot above, i need delete line between 10-28

                      alt text

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @pinuzzu99
                        last edited by Alan Kilborn

                        @pinuzzu99

                        Hmmmmmm, well, first, you don’t need the boomarks. I’m not sure if you put them in just for running the script, or if they were just already there.

                        Second, you have to read the prompt on the box: Enter first line # of range to delete: where, for your example, you would enter 10:

                        a5154e5b-d45c-4bde-9abf-f17d904af261-image.png

                        When you say OK to that, it will ask you for the last line, where you would enter 28:

                        117b228e-ca0a-4d4d-85af-b79156847b13-image.png

                        When you do that and press OK, it will then delete your range of lines, including the first and last (10 and 28 in this example will be gone after the final OK, as well as all lines in between).

                        You can press Cancel in either box to abort everything.

                        Did I really make it that hard to understand??

                        Sure, it could all be combined into one box, but then one has to think more about what to put in a single input box. The way I did it, you just follow the prompts.

                        By the way, your first line could have been 28 and your last line 10 and it would have worked the same way.

                        1 Reply Last reply Reply Quote 1
                        • Alan KilbornA
                          Alan Kilborn
                          last edited by

                          Hindsight looking at the script:

                          Where I call the lower function on the user_input variable probably isn’t the best place for it. They won’t fail with a ValueError and thus probably shouldn’t be part of that block. But the script DOES work as written (AFAICT), so I won’t provide a changed version.

                          1 Reply Last reply Reply Quote 0
                          • guy038G
                            guy038
                            last edited by

                            @pinuzzu99, @alan-kilborn All,

                            Sorry, I did not understand your need, correctly ! Indeed, you simply want, from a line, containing an e-mail address, delete all subsequent lines till the next line containing an e-mail address, excluded, don’t you ?

                            If so :

                            • Move to the line right after a line containing an e-mail address

                              • Manually

                              • Using the regex (?-s).+@.+\R\K, which places the caret at beginning of any line right after an e-mail address

                            • Now, use the following regex S/R to delete all lines till the next e-mail address line

                              • SEARCH (?s).+?(?=(?-s)^.+@)

                              • REPLACE Leave EMPTY

                            Note : I gave it a try, with 30,000 random lines between two lines containing an e-mail address and it correctly selected all this stuff in between and deleted it ;-))

                            Best Regards,

                            guy038

                            1 Reply Last reply Reply Quote 0
                            • pinuzzu99P
                              pinuzzu99
                              last edited by pinuzzu99

                              tanxs Alan, this was what i wanted!
                              and the bookmarks were only to make it clear the range i wanted to eliminate…

                              @guy038
                              tanxs for your reply. but i was hoping it could be done in one step…
                              anyway work well, always thanks for your appreciated help!

                              Alan KilbornA 1 Reply Last reply Reply Quote 1
                              • Alan KilbornA
                                Alan Kilborn @pinuzzu99
                                last edited by Alan Kilborn

                                @pinuzzu99 said in delete line between bookmark:

                                but i was hoping it could be done in one step

                                This implies that it is something you do often, so it might be worth recording multiple steps into a “macro” that you keep. This thread talks more about that.

                                Script notes: Using bof doesn’t make much sense – it is always going to be line 1 so why not just use 1? Also, I’ve thought of some extensions to the script. I could see myself using the script often. I’ll posts an enhanced version soon!

                                1 Reply Last reply Reply Quote 1
                                • pinuzzu99P
                                  pinuzzu99
                                  last edited by

                                  tanxs for your explanation on macros.
                                  but, if i understand correctly, if i record a macro, for example by deleting lines 10 to 20, this macro always repeats the same procedure…
                                  I instead have different txt, in which the lines to be deleted are always different…
                                  so i think in my specific case the elimination steps have to be done manually.
                                  is this correct?

                                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                                  • pinuzzu99P
                                    pinuzzu99
                                    last edited by

                                    @guy038
                                    also your string work, but this delete all line, including line which contains the email…
                                    instead i want delete the lines under the email, but leave this …

                                    1 Reply Last reply Reply Quote 0
                                    • Alan KilbornA
                                      Alan Kilborn @pinuzzu99
                                      last edited by

                                      @pinuzzu99

                                      I thought we were talking about several replacement operations when I brought up recording in macros. Other operations don’t lend themselves so well to “macroization”.

                                      1 Reply Last reply Reply Quote 0
                                      • guy038G
                                        guy038
                                        last edited by guy038

                                        Hello, @pinuzzu99 and All,

                                        You said in a previous post :

                                        also your string work, but this delete all line, including line which contains the email…
                                        instead i want delete the lines under the email, but leave this …

                                        My method does not delete any -mail address, assuming that you put the caret at the beginning of the first line, right after the line containing this e-mail address !

                                        Consider the input text :

                                        ....
                                        ....
                                        ....
                                        jasortrtn25hoon@hotmail.com:bartrall2335
                                        2017-07-08 12.35.03_5.jpg                         			32KB			             08/07/2017 19:34:57
                                        2017-07-08 12.35.03_8.jpg                         			71KB			             08/07/2017 19:34:57
                                        2017-07-08 12.35.10_4.jpg                         			70KB			             08/07/2017 19:35:04
                                        2017-07-08 12.48.43_15.jpg                        			84KB			             08/07/2017 19:48:41
                                        2017-07-25 01.22.59.jpg                           			102KB			            25/07/2017 08:22:59
                                        ======================================
                                        skysfsfff@gmail.cam:ksddsfdsfy37
                                        ....
                                        ....
                                        ....
                                        
                                        • If you run the search regex (?-s).+@.+\R\K, the caret should have moved at the beginning of the line 2017-07-08 12.35.03_5.jpg, with the calltip ^zero length match

                                        • Then, after running the search regex (?s).+?(?=(?-s)^.+@) all the lines, after the jasortrtn25hoon@hotmail.com, till the second e-mail address skysfsfff@gmail.cam excluded, should have been selected, then deleted after replacement !


                                        But, may be, you’ll prefer this other method, which need one operation, only !

                                        • Move , first, to a line containing an e-mail address, if necessary. Note that the caret can be at any position in that line, with an e-mail address !

                                        • Then, use the following regex S/R to delete all lines, after this 1st e-mail address till the next e-mail address, excluded

                                        SEARCH (?-s).*\R\K(?s:.+?)(?=^.+@)

                                        REPLACE Leave EMPTY

                                        Cheers,

                                        guy038

                                        1 Reply Last reply Reply Quote 0
                                        • pinuzzu99P
                                          pinuzzu99
                                          last edited by

                                          with first string work fine, but at one specific account all text it is selected, then deleted! but only in a specific case, maybe it contains characters that other accounts don’t contain …
                                          try with this txt: https://www.upload.ee/files/11106151/try_this.txt.html

                                          so, second string work, select all line that I want to eliminate, but then with the replace the lines are not deleted!
                                          i have record my screen, see video here: https://www.upload.ee/files/11106092/video_02.mp4.html
                                          maybe i do something wrong…

                                          1 Reply Last reply Reply Quote 0
                                          • guy038G
                                            guy038
                                            last edited by guy038

                                            @pinuzzu99 and All,

                                            Oh… I forgot to mention that you need to use the Replace All button , only. Do not use the Replace button which does not act as it should, when the regex contain any \K syntax. This is a general rule, available for any regex containing, at least, one \K syntax

                                            Best Regards,

                                            guy038

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