Replacing over multiple lines - all occurrences in file

Replacing over multiple lines - all occurrences in file

8
NewbieNewbie
8

    Jan 12, 2006#1

    Hi there,

    Hope someone can help me out with this problem.

    I want to delete a number of blocks of my document. The blocks I want to delete looks like this:

    Code: Select all

                    java.lang.ArrayIndexOutOfBoundsException: 65533
    	at defacto.calcscript.Lexer.next_token(Lexer.java:677)
    	at java_cup.runtime.lr_parser.scan(lr_parser.java:335)
    	at java_cup.runtime.lr_parser.parse(lr_parser.java:563)
    	at defacto.calcscript.Interpreter.parseScript
                    (empty line)
    The starting text will always be 'java.lang.xxxxx' and this text will always be the first part of the line (tabs and spaces might occur).

    'java.lang.xx' can also appear other places in the document but if 'java.lang.xx' is not found on the start of a line then the text must NOT be deleted.

    The end of the text part I want to delete will always be an empty line.

    I tried something like this: %[^t ]++^(java.lang*^)^(*%^p) - but it didn't work :-(

    Can anyone help me out here.

    thanks

    344
    MasterMaster
    344

      Jan 13, 2006#2

      Hi Krivo,

      try this one (deleteBlockRe):

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOn
      Top
      Loop 
      Find RegExp "^java.lang.*"
      IfFound
      Find RegExp Select "^$"
      IfNotFound
      ExitMacro
      EndIf
      Cut 
      Else
      ExitMacro
      EndIf
      EndLoop
      

      Code: Select all

      BLA empty line
      
      java.lang.ArrayIndexOutOfBoundsException: 65533
      at defacto.calcscript.Lexer.next_token(Lexer.java:677)
      at java_cup.runtime.lr_parser.scan(lr_parser.java:335)
      at java_cup.runtime.lr_parser.parse(lr_parser.java:563)
      at defacto.calcscript.Interpreter.parseScript
      
      
      bla java.lang.ArrayIndex I shound not be deleted bla
      
      
      java.lang.ArrayIndexOutOfBoundsException: 65533
      at defacto.calcscript.Lexer.next_token(Lexer.java:677)
      at java_cup.runtime.lr_parser.scan(lr_parser.java:335)
      at java_cup.runtime.lr_parser.parse(lr_parser.java:563)
      at defacto.calcscript.Interpreter.parseScript
      
      
      other stuff
      
      java.lang.ArrayIndexOutOfBoundsException: 65533
      at defacto.calcscript.Lexer.next_token(Lexer.java:677)
      at java_cup.runtime.lr_parser.scan(lr_parser.java:335)
      at java_cup.runtime.lr_parser.parse(lr_parser.java:563)
      at defacto.calcscript.Interpreter.parseScript
      
      Dont forget empty line at the end ...
      
      
      will look like this then:

      Code: Select all

      BLA empty line
      
      
      
      bla java.lang.ArrayIndex I shound not be deleted bla
      
      
      
      
      other stuff
      
      
      Dont forget empty line at the end ...
      
      
      If you do NOT want Unix regular expression in your environment, switch it back to off at the end.

      rds Bego
      Normally using all newest english version incl. each hotfix. Win 10 64 bit

      6,675585
      Grand MasterGrand Master
      6,675585

        Jan 13, 2006#3

        A multi-line UltraEdit/Unix regular expression Replace All cannot be used here. But this macro will do the job.

        Code: Select all

        InsertMode
        ColumnModeOff
        HexOff
        UnixReOff
        Loop 
        Find RegExp "%[ ^t]++java.lang"
        IfNotFound
        ExitLoop
        EndIf
        StartSelect
        Find Select "^p^p"
        IfSel
        Key UP ARROW
        Key UP ARROW
        Key END
        EndSelect
        Delete
        Else
        ExitLoop
        EndIf
        EndLoop
        UnixReOn
        Remove the last UnixReOn command, if you use regular expression in UltraEdit style by default instead of Unix style.
        For UltraEdit v11.10c and lower see Advanced - Configuration - Find - Unix style Regular Expressions.
        For UltraEdit v11.20 and higher see Advanced - Configuration - Searching - Unix style Regular Expressions.
        Macro commands UnixReOn/UnixReOff modifies this setting.

        And don't forget to enable the macro property Continue if a Find with Replace not found.

        This macro works for files with DOS terminated lines or Unix/Mac files which are converted automatically or after confirmation temporarily to DOS during editing. For opened Unix files in real Unix mode use ^n^n instead of ^p^p and for Mac files opened not in DOS mode use ^r^r.

        Update:
        Later with UE v12.00 the Perl regular expression engine was introduced in UltraEdit. With the Perl regular expression engine it is possible to do this task with a regular expression Replace All command.

        The Perl regular expression search string needed for the example is: (?s)^[\t ]*java\.lang\..*?\r\n[\t ]*\r\n
        Best regards from an UC/UE/UES for Windows user from Austria

        344
        MasterMaster
        344

          Jan 13, 2006#4

          Guten Morgen Mofi,

          seems we both stood up the same time ;-)

          As we can see, many ways leed to Rome.
          Krivo, just take the solution you like more :-)

          rds Bego
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          8
          NewbieNewbie
          8

            Jan 17, 2006#5

            Hi Rego and Mofi,

            Thank you very much for your input. You answer so fast - very impressive. Much appreciated!!

            I ended up making a macro which looked like below. I added a gotoline so I can replace in the whole document. Further, I added this line:
            Find RegExp Select "^p[ ^t]++^p" - just because I was editing the document and happened to press return at the last 'stacktrace' - and the macro would not find the indented line. But this was not part of the problem description - and will probably not be needed in reality :-)

            All the best to you guys

            Krivo

            Code: Select all

            InsertMode
            ColumnModeOff
            HexOff
            UnixReOff
            GotoLine 1
            Key HOME
            Loop 
            Find RegExp "%[ ^t]++java.lang"
            IfNotFound
            ExitLoop
            EndIf
            StartSelect
            Find RegExp Select "^p[ ^t]++^p"
            IfSel
            Key UP ARROW
            Key UP ARROW
            Key END
            EndSelect
            Delete
            Else
            ExitLoop
            EndIf
            EndLoop

              Apr 24, 2006#6

              Hi guys,

              Just to let you know. I changed the script to something a lot more simple which is much more efficient - much faster.

              Code: Select all

              InsertMode
              ColumnModeOff
              HexOff
              UnixReOff
              Find RegExp "%[ ^t]++java.lang*^p^p"
              Replace All ""
              Take care

              Krivo

              6,675585
              Grand MasterGrand Master
              6,675585

                Apr 25, 2006#7

                Hi Krivo!

                Yes, the *^p^p method works for selecting a block, but only because of a bug of UltraEdit. I have used this method in previous versions of my SortLanguage macro, but replaced it with the correct method in the current version.

                In help of UltraEdit you can read for * : Matches any number of occurrences of any character except newline.

                So your regular expression should only find a 2 line block where the first line starts with java.lang and the line below is a blank line. Well, you can use this faster replace but always take into consideration that you use a bug of UE and it maybe will not work in a future version of UE anymore when the bug is fixed.
                Best regards from an UC/UE/UES for Windows user from Austria