Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Multiline deletion

2. Help
2009-08-25
2012-11-13
  • Stefan Kurtz
    Stefan Kurtz
    2009-08-25

    Hallo,
    i want to delete every 2nd line so i selected them manually with the blue orb but how can i delete them actually? The context menu doesn't allow 'cut' or 'delete'?

    http://img267.imageshack.us/img267/5770/ggga.png

     
    • cchris
      cchris
      2009-08-26

      Another venue:
      1/ Add line numbers to your lines using Select All, then TextFX -> TextFX Tools -> Insert Line Numbers (that's a unique identifier)
      2/
      Search: ^\d\d\d\d\d\d\d[24680]
      Search mode = Regular expression
      Check "Mark Lines"
      Find all
      3/ Now all lines with an even line number are bookmarked.
      TextFX -> TextFX Tools -> Delete line numbers or first word
      4/ Search -> Delete bookmarked lines

      CChris

       
      • Fool4UAnyway
        Fool4UAnyway
        2009-08-26

        > 1/ Add line numbers to your lines using Select All,
        > then TextFX -> TextFX Tools -> Insert Line Numbers (that's a unique identifier)

        Mmm... Why didn't I post this? Simply because this is only a detour, involving only more steps, and in doing so only taking more time. This is the first _extra_ step.

        > 2/  Search: ^\d\d\d\d\d\d\d[24680]

        Do these line numbers have a fixed length?
        I would suggest using ^\d*[24680][^\d] in this case, or simply replace the [^\d] by a space character. It should be clear that the last digit is the last digit of the complete line number.

        > Search mode = Regular expression
        > Check "Mark Lines"
        > Find all

        > 3/ Now all lines with an even line number are bookmarked.

        If the line numbers have been recognized correctly. I assume this is the case.

        > TextFX -> TextFX Tools -> Delete line numbers or first word

        This is the seconde _extra_ step. If you would like to go this way, my suggestion is to perform this as the _last_ step. You are now removing the line numbers also from the lines that will be deleted anyway. This may be very time intensive as well. Performing this step at last will take half as much time.

        > 4/ Search -> Delete bookmarked lines

        This is what it is really all about. I guess a multiline regular expression trick would outperform this method.

         
    • Fool4UAnyway
      Fool4UAnyway
      2009-08-25

      Normally I would say you can use "multiline" regular expressions to achieve this. If you search you may find some tricks I reported about before.

      But this actually got me thinking. Would it make a difference whether I delete the lines from top to bottom or from bottom to top? Using regular expressions (usually) works only one way: from top to bottom, forward. When using a macro you could create it in such a way that it works its way up.

      Now why would this matter?

      If you are dealing with a lot of lines, removing every second line would perform the following steps. I am not sure this is the actual implementation in Scintilla, but this is what "bothers" me: when you delete a line from the "complete list of lines", all the lines below the deleted line have to be moved up in the list. Now, when you start deleting from the top, in total, you will have to move up more lines than when starting from the bottom...

      When using a macro you could simple define (record) it as "delete line, move two lines up" and perform (repeat) it, starting from the last second line, as many times as needed (the line number of this line divided by 2).

      Performing the macro "until the end of the document" won't work, I guess. Perhaps it would be an addition to implement this feature also the other way around: "until the start of the document".

      Perhaps it would also be a great addition to allow regular expressions searches to be performed upward, too.

      Now, if anyone is feeling like testing those situations for speed differences, I would be very much interested in the results.

       
      • Fool4UAnyway
        Fool4UAnyway
        2009-08-25

        Perhaps the fastest way to achieve your goal is by not deleting any lines at all...

        If all the first or second lines in your document have some unique identifier you could automatically bookmark (F2, the blue dot) them all by using the Find dialog.

        Next, you can perform copy and paste operations on all those bookmarked lines.
        You could delete them, but an alternative would be to copy only the lines you want to keep (and paste them) into a new document. This would result in only adding operations to the "list of lines" of the new document without any movements having to be performed.

        Again, I would be interested in any performance difference results of (all of) those methods.

         
        • Fool4UAnyway
          Fool4UAnyway
          2009-08-25

          You can find the copy and paste operations for bookmarked lines at the bottom of the Edit menu (I believe). I guess that's what you were looking for in the first place.

          Looking at your screen print, it _looks like_ ": Exit" and ": Enter" may be unique identifiers by which you could (de)select lines. However, there are also other lines in-between those pairs.

          Some bookmarked lines contain the "Exit" identifier and some "Enter". You may have been mistaken in bookmarking them.

          If you can or want to select lines by a unique identifier, that is the safest way to go. The macro solution won't work in this case, that is, if there are also other lines in the document you may (not) want to keep.

           
  • Rich
    Rich
    2012-10-24

    Search/Bookmark - Removed Bookmarked lines