Checking a file for a list of strings

(imported topic written by bchae91)

I have 3 folders:

C:\folder1

C:\folder2

C:\folder3

in each of these folders is a text file called file.txt

Each of these text files will have a line or lines (unknown) containing the string “RealValue=X”

The value of X can be any random number.

The relevance I’m going for is this:

every line with “RealValue=” in C:\folder2\file.txt and C:\folder3\file.txt should also exist in C:\folder1\file.txt. If not, the relevance returns false.

I have this to return the lines containing “RealValue=”

(lines whose (it contains “RealValue=”) of file “C:\folder2\file.txt”)

(lines whose (it contains “RealValue=”) of file “C:\folder3\file.txt”)

But i’m not sure how i should go about comparing these to C:\folder1\file.txt.

(imported comment written by NoahSalzman)

This sounds like a job for tuples. Here is a simplistic example:

Q: (item 0 of it = item 1 of it) of (“A”, “B”)

A: False

Q: (item 0 of it = item 1 of it) of (“A”, “A”)

A: True

Now lets check item 0 compared against two other items:

Q: (item 0 of it = item 1 of it AND item 0 of it = item 2 of it) of (“A”, “A”, “B”)

A: False

Q: (item 0 of it = item 1 of it AND item 0 of it = item 2 of it) of (“B”, “A”, “A”)

A: False

Q: (item 0 of it = item 1 of it AND item 0 of it = item 2 of it) of (“A”, “B”, “C”)

A: False

Q: (item 0 of it = item 1 of it AND item 0 of it = item 2 of it) of (“A”, “A”, “A”)

A: True

Now, you can plug in lines of files:

Q: (item 0 of it = item 1 of it AND item 0 of it = item 2 of it) of ((lines whose (it contains “RealValue=”) of file “c:\folder1\file.txt”), (lines whose (it contains “RealValue=”) of file “c:\folder2\file.txt”), (lines whose (it contains “RealValue=”) of file “c:\folder3\file.txt”))

If there are mis-matching numbers of lines that contain “RealValue” you will get a result of false, but I believe that is what you want.

(imported comment written by bchae91)

I don’t think this works correctly. Here is an example that should return true:

C:\folder1\file.txt contains

RealValue=1

RealValue=3

RealValue=2

RealValue=6

C:\folder2\file.txt contains

RealValue=2

RealValue=1

RealValue=3

C:\folder3\file.txt contains

RealValue=2

RealValue=1

Here is an example that should return false:

C:\folder1\file.txt contains

RealValue=1

RealValue=3

RealValue=2

C:\folder2\file.txt contains

RealValue=2

RealValue=4

RealValue=3

C:\folder3\file.txt contains

RealValue=2

RealValue=1

And another that should return false:

C:\folder1\file.txt contains

RealValue=1

RealValue=3

RealValue=2

C:\folder2\file.txt contains

RealValue=2

RealValue=1

RealValue=3

C:\folder3\file.txt contains

RealValue=4

RealValue=1

(imported comment written by NoahSalzman)

Ha! Yeah… sorry, the relevance I provided is completely wrong for your use case… not quite sure how to fix that. Perhaps Ben or Jesse (et al.) can point us in the right direction.

If there is no “clever” way to fix it I fear that there might be a combinatorial explosion of code (just doing a brute force check). To that end, how many “RealValues” do you have per file?

(imported comment written by bchae91)

the number of “RealValues” per file can vary. Anywhere from 1 to 20.

(imported comment written by Lee Wei)

Hi Bryant,

Looks like a good use of the set operator.

  • Combine the values in folder2 and folder3 into one set
  • Set1 contains Set2 should be all we need to do the comparison

set of (lines of file “c:\folder1\file.txt”) contains set of (lines of file “c:\folder2\file.txt”; lines of file “c:\folder3\file.txt”)

Lee Wei

(imported comment written by Lee Wei)

I just went back and see that you might need to pull out only the lines with RealValue=.

But I think you know how to add the whose clause into the statements. :slight_smile:

Lee Wei