Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search text file for string 1

Status
Not open for further replies.

jlozan

MIS
Oct 28, 2009
4
US
I’m trying to create a script to look in a text file and search for something. Then, return a value of “0” if it finds it and returns a value of “1” if it doesn’t. I've found something on scriptcenter, but it just returns the value that I search for. I've modified that script to just output 0 if true and 1 is false, but then I just get a 1 or 0 for each line in the file. I was hoping for the sum of everything which would be 0 if it wasn't found and some number greater than 0 if it was.

Here is what I have so far.

Code:
Const ForReading = 1

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "ctxsta.dll"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("F:\Program Files\Citrix\Secure Gateway\conf\httpd2.conf", ForReading)

Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)  
    If colMatches.Count > 0 Then
        Wscript.Echo 0
    Else Wscript.Echo 1 
    End If
Loop

objFile.Close
 
Code:
[blue]Const ForReading = 1

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "ctxsta.dll"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("F:\Program Files\Citrix\Secure Gateway\conf\httpd2.conf", ForReading)
Wscript.Echo -1 * objRegEx.Test(objFile.ReadAll)

objFile.Close[/blue]
 
wow - that was quick - thanks!

It works, can you briefly explain what this line does?

Wscript.Echo -1 * objRegEx.Test(objFile.ReadAll)
 
ok, I have a slight problem. when i search for the string "SSLProtocol +TLSv1", I get a negative result even though I know its in the file. If I change it to only "SSLProtocol", it succeeds. if I change it to "+TLSv1", it fails with an Unexpected quantifier error.

Is the + a special character of some sort?

anyway to get this to give a positive result for "SSLProtocol +TLSv1" ?

Thanks so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top