Searching a file for a line containing two seperate things

(imported topic written by mhindman91)

Hello,

I am trying to search a file for lines that have TWO individual entries in the line. Essentially i want to know if a string is in the line however if the line is commented out i would like to ignore it … some what of an and statement for hte search Here is what i have that works for ONE string search found in hte file but i cannot figure out how to put two in there. The second thing MUST be on hte same line as hte first thing

blah blah blah SKL ENGAGE (should return to me)

’ blah blah blah SKL ENGAGE (should not count because its commented out

if exists folder (“C:\SC” & value “Active” of key “HKEY_LOCAL_MACHINE\SOFTWARE\bob\Install\MachineController” of the registry as string & “\config”) then if number of files whose (content of it as lowercase contains “skl engage”) of folder (“C:\SC” & value “Active” of key “HKEY_LOCAL_MACHINE\SOFTWARE\bob\Install\MachineController” of the registry as string & “\ct_src”) > 0 then concatenation “,” of names of files whose (content of it as lowercase contains “skl engage”) of folder (“C:\SC” & value “Active” of key “HKEY_LOCAL_MACHINE\SOFTWARE\bob\Install\MachineController” of the registry as string & “\ct_src”) as string else “” else “”

(imported comment written by NoahSalzman)

Does this work for you? It’s hard to see, but that is a single quote in the “does not start with” section.

lines whose (it contains “foo” and it contains “bar” and it does not start with “’” ) of file “c:\foo.txt”

(imported comment written by mhindman91)

basically if the whole file has SKL ENGAGE i want to report it … anywhere in the file, however if hte line that it finds it on has a ’ at the begenning then dont count it

(imported comment written by NoahSalzman)

Try this:

if (not exists folder (“C:\SC” & value “Active” of key “HKEY_LOCAL_MACHINE\SOFTWARE\bob\Install\MachineController” of registry as string & “\config”)) then “” else (if (length of it > 0) then it else “”) of (concatenation ", " of (names of (files of folder (“C:\SC” & value “Active” of key “HKEY_LOCAL_MACHINE\SOFTWARE\bob\Install\MachineController” of registry as string & “\config”) whose (exists lines whose (it as lowercase contains “skl engage” and it does not start with “’”) of it)))

(imported comment written by mhindman91)

Q: if (not exists folder (“C:\SC” & value “Active” of key “HKEY_LOCAL_MACHINE\SOFTWARE\bob\Install\MachineController” of registry as string & “\config”)) then “” else (if (length of it > 0) then it else “”) of (concatenation ", " of (names of (files of folder (“C:\SC” & value “Active” of key “HKEY_LOCAL_MACHINE\SOFTWARE\bob\Install\MachineController” of registry as string & “\config”) whose (exists lines whose (it as lowercase contains “skl engage” and it does not start with “’”) of it))))

E: The expression could not be evaluated for an unknown reason

I noticed that you were unbalanced on the () so i tried to find wehre it went and it seemed to fit at the end so i added it there but it doesnt get anything other than the above one… the first part works i broke it out and it gives no ct_src folder if it doesnt exist but the rest i dont know how to test individually :frowning:

(imported comment written by NoahSalzman)

Yeah, I hacked that together without testing it and missed a (). This should work, if you are succesfully able to replace (“C:”) with the folder you want.

q: if (not exists folder (“C:”)) then “” else (if (length of it > 0) then it else “”) of (concatenation ", " of (names of (files of folder (“C:”)) whose (exists lines whose (it as lowercase contains “skl engage” and it does not start with “’”) of it)))

A:

q: if (not exists folder (“C:\Users\Noah Salzman”)) then “” else (if (length of it > 0) then it else “”) of (concatenation ", " of (names of (files of folder (“C:\Users\Noah Salzman”)) whose (exists lines whose (it as lowercase contains “skl engage” and it does not start with “’”) of it)))

A: bar.txt, foo.txt

(imported comment written by mhindman91)

wow works like a charm :slight_smile: Thanks again this saves me a lot of time. Thanks again!

(imported comment written by mhindman91)

Oh one more thing how can i trim the string

’ SKL ENGAGE (it ignores this ok)

'SKL ENGAGE (it still reports this)

i am playing with as trimmed string but it doesnt like to be combined with (it as lowercase trimmed string)

(imported comment written by NoahSalzman)

Well, if you know for certain that the apostrophe is always going to be right in front of the “skl” then you can do something like this:

Q: (it contains “skl” and it does not start with “’” and it does not contain “'skl”) of " skl"

A: True

Q: (it contains “skl” and it does not start with “’” and it does not contain “'skl”) of “’ skl”

A: False

Q: (it contains “skl” and it does not start with “’” and it does not contain “'skl”) of " 'skl"

A: False

Q: (it contains “skl” and it does not start with “’” and it does not contain “'skl”) of " ’ skl"

A: True

Note that the last example is a case that we can’t handle by simply adding

and it does not contain “'skl”

.

Trimmed string will only take off trailing white space, so if you need to handle the last case – where the apostrophe may have leading and trailing whitespace – then we probably have to use regex.

(imported comment written by mhindman91)

i used left trim because i know the comment has to be the first char that is non white space on the line