Search string and copy all found lines/strings to clipboard or new file

Search string and copy all found lines/strings to clipboard or new file

4
NewbieNewbie
4

    Feb 25, 2005#1

    Hi,

    I need a small macro. Basically an automated version of the search where you can list all lines containing the searched string and copy all of them to clipboard.

    Right now I'm doing this... it works but it takes damn long.. there must be away to do this faster...

    Top
    Loop
    Find "search string"
    IfFound
    SelectLine
    CopyAppend
    Else
    ExitLoop
    EndIf
    EndLoop

    Also is there a way to avoid the popup window "Search string not found" in the end?

    regards
    Matthias

    21
    Basic UserBasic User
    21

      Mar 03, 2005#2

      Your largely doing what I would do. The one thing I might do different is do an expression search.This would be better because UE's kernel would be highlighting everything we want to append into the clipboard as part of the search. This would elminate a few lines of macro code from your loop processing. In the example below, we are searching for lines containg string "asdf" (no quotes).

      The macro places a blank line at end of file so we have that as an anchor. Clears clipboard, searches file in a loop, appending results into clipboard. When were done we delete that blank line we inserted. Clipboard contains what you want.

      The macro itself should have a check in the macro attribute "continue if find with replace not found". This will eliminate your error dialog box at EOF.

      Does this work any faster?


      Bottom
      Key END
      "
      "
      Top
      ClearClipboard
      Loop
      Find RegExp "%*asdf*^p"
      IfFound
      CopyAppend
      Else
      ExitLoop
      EndIf
      EndLoop
      Bottom
      Key END
      Key BACKSPACE

      4
      NewbieNewbie
      4

        Nov 02, 2006#3

        I'm trying to create a macro that finds all occurrences of a particular string in a file and copies just those lines to a new file.

        I used macro recording to capture the exact steps I do manually but the function does NOT record the "Clipboard" button press in the "Lines containing find string" window (see the resulting captured macro listing below).

        InsertMode
        ColumnModeOff
        HexOff
        UnixReOff
        Find MatchCase PreserveCase "String"
        NewFile
        Paste

        I tried manually adding a "Clipboard 0" command right before the "NewFile" but that doesn't work.

        Does anyone know the trick to make this work?

        6,686585
        Grand MasterGrand Master
        6,686585

          Nov 02, 2006#4

          List Lines Containing String is a find option which cannot be used from a macro because it requires user interaction. The macro solution is to use a loop with CopyAppend command. The following macro runs always from top of the file and needs the macro property Continue if a Find with Replace not found or Continue if search string not found enabled.

          InsertMode
          ColumnModeOff
          HexOff
          Bottom
          IfColNumGt 1
          "
          "
          IfColNumGt 1
          DeleteToStartofLine
          EndIf
          EndIf
          Top
          Clipboard 9
          ClearClipboard
          Loop
          Find MatchCase "String"
          IfFound
          SelectLine
          CopyAppend
          Else
          ExitLoop
          EndIf
          EndLoop
          NewFile
          Paste
          ClearClipboard
          Clipboard 0

          A variant of above which copies only the found string to clipboard with an additional CR/LF (or just CR or LF according to file type and edit mode) to get just a list of found strings. That makes only sense for a regular expression search. Unfortunately it is not possible to simply append a string to clipboard in the macro environment. (Scripts can do it.) So always the line termination must be inserted and cut with append to the clipboard.

          InsertMode
          ColumnModeOff
          HexOff
          UnixReOff
          Top
          "
          "
          SelectToTop
          Clipboard 8
          Cut
          Clipboard 9
          ClearClipboard
          Loop
          Find RegExp "enter regex search string here"
          IfFound
          CopyAppend
          EndSelect
          Key LEFT ARROW
          Key RIGHT ARROW
          Clipboard 8
          Paste
          StartSelect
          Key UP ARROW
          Key END
          Clipboard 9
          CutAppend
          Else
          ExitLoop
          EndIf
          EndLoop
          NewFile
          Paste
          ClearClipboard
          Clipboard 8
          ClearClipboard
          Clipboard 0

          A third version is like above. It just copies the found strings, but without appending immediately the line terminations. So in the new file there are lots of found strings on one single line and nearly the same regular expression as used before is used now to insert the line terminations. The example code below is for the UltraEdit regular expression engine for DOS files. For Unix or Perl regexp use just () instead of ^(^) and \1 instead of ^1. For UNIX files not temporarily convert to DOS on load use ^n (UE regexp) respectively \n (Unix/Perl regexp).

          InsertMode
          ColumnModeOff
          HexOff
          UnixReOff
          Top
          Clipboard 9
          ClearClipboard
          Loop
          Find RegExp "enter regex search string here"
          IfFound
          CopyAppend
          Else
          ExitLoop
          EndIf
          EndLoop
          NewFile
          Paste
          Top
          Find RegExp "^(enter regex search string here again^)"
          Replace All "^1^p"
          ClearClipboard
          Clipboard 0
          Best regards from an UC/UE/UES for Windows user from Austria

          4
          NewbieNewbie
          4

            Re: Search string and copy all found lines to clipboard

            Nov 02, 2006#5

            Thanks :)
            I'll fine-tune it to my needs :wink: