Delete all lines between 2 pre-defined texts

Delete all lines between 2 pre-defined texts

2
NewbieNewbie
2

    Mar 10, 2006#1

    Hello,

    I'd like to know if it is possible to create a macro to delete all the lines between 2 pre-defined texts such as on example below:

    AAAA
    bla bla bla
    bla1 bla2 bla3
    asdfg lkjhg
    FFFF


    AAAA
    blad blas blaa
    blax blay blaz
    12345
    FFFF


    AAAA
    888888
    bla1 bla2 bla3
    45656
    FFFF

    I want to create a macro to remove all the lines between the line with AAAA and the line with FFFF (this 2 must remain on the original file). So the result would be

    AAAA
    FFFF
    AAAA
    FFFF
    AAAA
    FFFF

    btw, the number of lines between this two points can be variable

    Thanks for the help

    6,686585
    Grand MasterGrand Master
    6,686585

      Mar 11, 2006#2

      That's simple for me, but very difficult for most other users because they did not read the manual and so don't know about the superb Find Select feature.

      If you hold the SHIFT key while pressing the Find Next button in the find dialog everything from current cursor position to end of the found search string is selected. And it's not really surprising, that this Find feature is also available via macro command Find. What is not described in the help is that you have to release the SHIFT key shortly if you want to modify the selection further with the cursors after the find (for example unselect the founded search string).

      With this knowledge you now should be able to simple record the macro. But for me it's more difficult to write and post the macro code because I don't know some of your settings. So I have to think about all possible settings which could have influence on the macro execution and have to add extra code to make sure the macro works under all possible configurations.

      The following macro is independet of macro property Continue if a Find with Replace not found. You could discard the IfNotFound part and the Else part of the IfSel code, if you do not enable this property.

      Because of the special Key HOME handling in the macro code this macro is also indepedent of the current setting of option Home Key Always Goto Column 1 at Configuration - Editor - Miscellaneous. I don't know if you have enabled it or not and if you have preceding white-spaces in the line AAAA and/or FFFF.

      InsertMode
      ColumnModeOff
      HexOff
      Top
      Loop
      Find "AAAA"
      IfNotFound
      ExitLoop
      EndIf
      Key HOME
      IfColNumGt 1
      Key HOME
      EndIf
      Key DOWN ARROW
      StartSelect
      Find Select "FFFF"
      IfSel
      Key HOME
      Key HOME
      EndSelect
      Delete
      Else
      EndSelect
      ExitLoop
      EndIf
      EndLoop
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Mar 13, 2006#3

        It works perfectly!

        Thanks for your help!!