Tapatalk

Find in files: Find all files matching term1 AND term2

Find in files: Find all files matching term1 AND term2

17
Basic UserBasic User
17

    Jan 27, 2006#1

    Hello,

    I want to search multiple files and list those who match both search terms.

    Example:
    I want to search for "John" and "Smith" in multiple files. Now there are 4 possibilites:

    - contains neither John nor Smith
    - contains John
    - contains Smith
    - contains John & Smith

    I just want the files from the last category.

    Is that possible?

    6,685587
    Grand MasterGrand Master
    6,685587

      Jan 27, 2006#2

      I don't know, if there is a solution with a single regular expression search. Maybe, it depends on the structure of your files. You have forgotten to give us some examples which is unfortunately typical for new forum users.

      So I have quickly developed a macro which is able to do this independent of the file structure.

      The first part searches for "John". You can modify the first FindInFiles command to your needs (open files or specified files in a directory, regexp, ...), but it must write the result to a log file. This macro is taken from Send all open file names to tool.

      The second part is taken from How do you run a Macro on open files?
      It closes all open files except the search result file.

      The third part I have developed new. It opens all files from the first search. So after the 3rd loop all files are opened which contain the word "John".

      The last part is simply a Find In All Open Files for "Smith". You can modify all parameters of this FindInFiles command, but it must run on all open files.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      FindInFiles Log OpenFiles "" "" "John"
      Loop
      Find RegExp Up "%Search complete, found *^p"
      IfFound
      Delete
      ExitLoop
      Else
      NextWindow
      EndIf
      EndLoop
      Top
      Find "----------------------------------------^p"
      Replace All ""
      Find RegExp "%Find *^p"
      Replace All ""
      Find RegExp "%Found *^p"
      Replace All ""
      Find RegExp "/[0-9]+:*$"
      Replace All ""
      SortAsc IgnoreCase RemoveDup 1 -1 0 0 0 0 0 0

      Top
      "ThisIsTheSearchResultWindow"
      Loop
      NextWindow
      Top
      Find MatchCase "ThisIsTheSearchResultWindow"
      IfFound
      Delete
      ExitLoop
      Else
      CloseFile
      EndLoop

      Clipboard 9
      Loop
      IfEof
      CloseFile NoSave
      ExitLoop
      Else
      StartSelect
      Key END
      Cut
      Key DEL
      EndSelect
      Open "^c"
      NextWindow
      EndIf
      EndLoop
      ClearClipboard
      Clipboard 0
      FindInFiles OutputWin OpenFiles "" "" "Smith"
      UnixReOn

      Remove the last red 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.
      Best regards from an UC/UE/UES for Windows user from Austria