Macro to Delete Lines Containing Selected Text?

Macro to Delete Lines Containing Selected Text?

5
NewbieNewbie
5

    Sep 23, 2011#1

    Hello,

    I use UltraEdit often to parse through very large log files, and one task I'm constantly trying to streamline is the removal of uninteresting/repetitive lines.

    Right now, I'm using the "Delete Lines Containing String" macro from the downloads section, but have found that it is often so slow that it's faster for me to simply copy the text, and replace all with the following RegEx: ^.*<PASTE>.*$

    I end up doing this over and over again, and would like to streamline the Replace All process with a macro, using the currently selected text to delete all lines containing that text. However, when I try to use ^s in the macro along with the RegEx above, it never finds anything. I'm not sure what I'm missing. Current macro contents are below.

    Of course, finding a way to speed up the script, which already works but is quite slow, would also fit my needs.

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    PerlReOn
    Find RegExp AllFiles "^.*^s.*$"
    Replace All ""
    
    Thanks in advance for any tips.

    6,686585
    Grand MasterGrand Master
    6,686585

      Sep 23, 2011#2

      ^s and ^c are supported only when running a non regular expression replace or an UltraEdit regular expression replace. The UNIX and the Perl regexp engines don't support that UltraEdit special.

      So you can use only

      InsertMode
      ColumnModeOff
      HexOff
      UltraEditReOn
      Find RegExp AllFiles "%*^s*$"
      Replace All ""


      or to delete the (DOS/UNIX) lines completely

      InsertMode
      ColumnModeOff
      HexOff
      UltraEditReOn
      Find RegExp AllFiles "%*^s*^r++^n"
      Replace All ""


      But please note that the last line of a file must have also a line termination to get it also deleted with that macro. And important to know is also that the selected string is interpreted as UltraEdit regular expression string. So if the selected string contains any UltraEdit regular expression character, the macro works different as you might expect. As long as you use the macro just for deleting lines containing a word(s), it will work for you.

      5
      NewbieNewbie
      5

        Sep 23, 2011#3

        Thanks so much yet again Mofi.

        It's still not working for me for some reason.

        I'm using the first code block you gave me:
        InsertMode
        ColumnModeOff
        HexOff
        UltraEditReOn
        Find RegExp AllFiles "%*^s*$"
        Replace All ""

        But when I select the word Microsoft, it's still not removing any lines. If I change the code to include
        Find RegExp AllFiles "Microsoft"
        I get exactly what I expect the behavior to be when selecting and using ^s.

        When I run the macro, the Cancel Operation box pops up very briefly, but nothing is ever removed.

        What am I missing?

        Thank you!

          Sep 23, 2011#4

          Nevermind. I replaced the *'s in the UltraEdit RegEx with ?++ and now it's working as expected. My apologies, not as familiar with UE RegEx as Perl.

          Thanks again, Mofi, for identifying the main issue with this macro!

          6,686585
          Grand MasterGrand Master
          6,686585

            Sep 23, 2011#5

            That difference in behavior is interesting. I have run some tests and could see that indeed the line with the selected text is not cleared with %*^s*$ while it is cleared with %?++^s?++$ and moving the caret to next line not cleared.

            * is non-greedy while ?++ is greedy. But there should be no difference in this case. It should not matter if first * matches everything up to first occurrence of selected text and second * matches everything to end of line while first ?++ matches everything up to last occurrence of selected text and second ?++ matches everything to end of line.

            I will report this to IDM by email. The IDM developers must evaluate it and decide if this difference in behavior is a bug or by design.

            Edit on 2011-10-13: The issue with %*^s*$ not deleting also the line with the selected text was fixed with UE v17.30.0.1002 (first public release of UE v17.30).