Negating search criteria

Negating search criteria

2
NewbieNewbie
2

    Oct 14, 2004#1

    Hello,

    I have a file containing the output of an Ant script, and I'd like to strip out every line that doesn't end with a colon. For example:

    Code: Select all

    03 > backup:
    04 >     [echo] Pre-install backup for 4.0.0.49 complete.
    05 >
    Line three above is matched by the expression .*:$ but I really want to match lines four and five, so I can search-and-replace them with nothing ("").

    It would make a handy feature for a future version of UltraEdit to have a "negate" check-box option in the search options dialogue, so everything that didn't match the search criteria would be found.

    Similarly, it would be handy to have a "compress" feature that would eat any repeating newline characters. So if I had a file that contained two lines separated by 'x' number of sequential newline characters (blank lines), UltraEdit would remove all but one newline character, and my two lines would end up being one-after-the-other.

    For now, I just use this command:

    C:\> type build.log | perl -e 'while (<STDIN>){print $_ if ($_ =~ /:$/ && $_ !~ /^\s/);}'

    Just some thoughts as I work through my Thursday. It may already be possible to do these things in UltraEdit, and I just don't know about it. I thought it wouldn't hurt to post them here, anyway. Best regards,


    George Formby

    6,613548
    Grand MasterGrand Master
    6,613548

      Oct 15, 2004#2

      The regular expression "%[~:^p]+^p" in UltraEdit style finds all lines, which has no colon and are deleted with replace "". This would be enough for your example. But if your file contains also lines with a colon inside the line, this expression is not enough. Following macro can do the job:

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Bottom
      IfColNum 1
      Else
      "
      "
      EndIf
      Top
      Loop
      Key END
      Key LEFT ARROW
      IfCharIs ":"
      Key HOME
      Key DOWN ARROW
      Else
      DeleteLine
      EndIf
      IfEof
      ExitLoop
      EndIf
      EndLoop


      Empty line eater (UltraEdit style):

      Find What: ^p[^p]+
      Replace With: ^p
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Oct 15, 2004#3

        Thank you Mofi; that's incredible!

        Ihr schöner und fortgeschrittener Stil zum Schreiben von Code ist ja viel mehr als ich erwartet habe (in Wirklichkeit habe ich gar nichts als Antwort zu bekommen erwartet, weil ich vermutet habe, dass diese Fähigkeiten in UltraEdit nicht möglich sind und ich versuchte nur einen zukünftigen Entwicklungsvorschlag vorzustellen). Ich Dummer! Ich habe fast keine Ahnung wie dieses "%[~:^p]+^p" Regular Expression-Stil funktioniert aber ich werde jetzt versuchen mehr davon bei Google zu lernen. Sehr cool.

        I hope that I didn't appear aloof in my original post. I was in a hurry to get other things done and didn't think to add niceties like "does anybody else know of a way to accomplish what I am trying to do?" I assumed that it wasn't possible, which of course is always bad to do, especially with a tool as flexible and implicitly powerful as UltraEdit.

        Thank you again, Mofi. The more I learn about UltraEdit the more I appreciate what a fantastic tool it is, and just how much it is worth registering, especially when compared to other shareware editors out there.

        Viele Grüße aus Vancouver, Kanada

        George