Matching multiple items in a file

(imported topic written by jeremytoo)

I have two files.

file A has a list of items which I want to find.

file B contains a variety of items in a random order, one thing per line.

I want to return TRUE

only

if file B does not contain all entries from file

So, for example:

if file A has: “lazy fox brown”

and file B has:

the

quick

red

fox

jumped

over

the

lazy

brown

dog

I want to return negative.

if, however, file A has “spock kirk scotty” and file B has:

rand

brought

captain

kirk

coffee

but

did

not

bring

anything

for

spock

I would return relevant (file B is missing ‘scotty’)

I can’t figure how to check for all the items w/o a loop, and since relevance has no loops…

any ideas are greatly appreciated.

(imported comment written by NoahSalzman)

You could do something like this:

number of ((lines of file “file_a.txt”, lines of file “file_b.txt”) whose (item 0 of it is item 1 of it)) is 3

file_a.txt – lazy, fox, brown – has to have each word on its own line.

(imported comment written by DTan)

Alternatively, you can use “set”:

number of elements of ((set of ((it as string) of lines of file “file_a.txt”)) - set of ((it as string) of lines of file “file_b.txt”)) > 0

(imported comment written by jeremytoo)

Noah, based on your approach, I can do some of what I need with:

(number of ((lines of file “file_a.txt”, lines of file “file_b.txt”) whose (item 0 of it is item 1 of it)) as integer) = (number of lines of file “file_a.txt” as integer)

then I don’t have to know how many items are in file_a.

The only drawback there is that they have to be on separate lines, and I’d rather be able to pull the list of desired elements out of a variable, like a client setting. I suspect sets may be useful for this, but am unsure as to how I would go about using them

(imported comment written by NoahSalzman)

Well, if you can give us more details about what the data looks like and where we are pulling it from we can certainly help with the parsing. Are you saying that the data represented by “file_a.txt” is actually a bunch of client settings?

(imported comment written by jeremytoo)

a single setting of usernames separated by spaces.

the actual data I’m checking in file b is /etc/ftpusers.

it looks like this:

username1

username2

username3

username4

the list of usernames would look like this:

“usernameX usernameY usernameZ”

(imported comment written by SystemAdmin)

andersje,

This might work for you.

Q: (IF (number of elements of item 0 of it < number of elements of item 1 of it) THEN (it whose (multiplicity of it = 1) of unique values of elements of (item 0 of it;item 1 of it)) else (nothings)) of (intersection of (item 0 of it; item 1 of it), item 0 of it) of (set of (substrings separated by " " of concatenation " " of (lines of file"c:\temp\file_a.txt")), set of (lines of file “c:\temp\file_b.txt”))

A: bob

A: scotty

File A can have entries on a single line (delimited with spaces) or on multiple lines. File B is currently limited to single words per line, but could be modified to adjust for varying input formats.

-Jim

P.S. Forgot to add I put in the name of a ‘redshirt’ character in the file A list when I tested for entries on multiple lines.

(imported comment written by NoahSalzman)

Work a redshirt reference into a Forum post? You Khan’t do that.