How to check a file to see if it contains to separate strings

(imported topic written by bchae91)

I’ve been trying to create a relevance that checks to see if any file in a folder contains two strings. For example, I want to check all the files in folder c:\temp to see if there is any file that contains “test1” and “test2”. These two strings could be on any anywhere in the file and could appear mutiple times as well. I tried to do this below but obviously it will not work because it will still return true if all of the files cumulatively contain “test1” and “test2”.

exists (lines whose (it contains “test1”) of files of folder “C:\temp”) and exists (lines whose (it contains “test2”) of files of folder “C:\temp”)

(imported comment written by BenKus)

Try this:

exists file whose (exists line whose (it contains “test1”) of it and exists lines whose (it contains “test2”) of folder “C:\temp”

Ben

(imported comment written by bchae91)

That doesn’t seem to work. You also have an extra ( that isn’t closed.

(imported comment written by NoahSalzman)

This works for me using text files… haven’t tried with other types of files:

exists file whose

(

(exists line whose (it contains “test1”) of it)

and

(exists line whose (it contains “test2”) of it)

)

of folder “c:\temp”

(imported comment written by jr6591)

How intensive is this search? I got it to work but i was wondering if somehow, it could detect something a little more detailed. I’m looking for a value in a text file that has a number. For example, Policy Object - Health [5]. The number is not specific to PC’s, so the text file can have this information but the number can change from anywhere from 3 to over 10. I don’t want to use the and scenario as in this example - Q: exists file whose ( (exists line whose (it contains “Policy Object - Health [5]”) of it) and (exists line whose (it contains “Policy Object - Health [6]”) of it) )of folder “C:\Program Files\PO”

ANy thoughts on how to do this and then show this in an Analysis?

Thanks

(imported comment written by NoahSalzman)

There are a couple ways to approach this. The simplest is:

lines whose (it contains “Policy Object - Health [”) of file “c:\test.txt”

That will return the an entire line if it matches.

Another way, if you just want the number, is:

preceding texts of substrings “]” of following texts of substrings “Policy Object - Health [” of (lines of file “c:\test.txt”)

Lastly, you can use regex:

parenthesized part 1 of matches (regex (“Health [(0-9)]”)) of lines of file “c:\test.txt”

(imported comment written by jr6591)

Noah … Thanks. I used you’re second suggestion.