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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter info using RegExp 1

Status
Not open for further replies.

Rambeaux007

IS-IT--Management
May 4, 2005
23
US
This script executes the HPONCFG.exe then parses thru it's output. The problem lies when I try to filter out the information between the quotes. (<IP_ADDRESS VALUE = "100.148.8.182"/>) I need to get the regexp working so I can get the information out of the quotes. Not just for IP but other information as well. Can someone assist me? If strings work but they don't filter out all the other characters.



Option Explicit
Dim strComputers, INPUT_FILE_NAME
Dim ObjShell
Dim strCurrentLine
Dim FileFSO,objFile
Dim objRegEx
Dim IP_Address, colMatches

On Error Resume Next
'*********************************************************************************
Set ObjShell = CreateObject("WScript.Shell")
'Executes HPONCFG.exe in order to gather iLO config
ObjShell.Run("%comspec% /c hponcfg /W c:\Verify\%computername%_iLO.txt"), 1, True

'*********************************************************************************
'INPUT_FILE_NAME = Server List Location

INPUT_FILE_NAME = "c:\Verify\iLO.txt"
Const FOR_READING = 1
Set FileFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = FileFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)

'**********************************************************************************
Do Until objFile.AtEndOfStream
strCurrentLine = objFile.ReadLine
If InStr(strCurrentLine, "<IP_ADDRESS VALUE") <> 0 Then

Set objRegEx = New RegExp
'Sets Pattern for lookup
objRegEx.Pattern = "\[((\d+\.){3}\d+)\]"
Set colItems = objRegEx.Execute(strCurrentLine)
If colMatches.Count > 0 Then

For Each objItem In colItems
WScript.Echo ObjItem.SubMatches(0)

Next

End If

Elseif InStr(strCurrentLine, "<GATEWAY_IP_ADDRESS") <> 0 Then
wscript.echo strCurrentLine
Elseif InStr(strCurrentLine, "NIC_SPEED VALUE") <> 0 Then
wscript.echo strCurrentLine
Elseif InStr(strCurrentLine, "<FULL_DUPLEX VALUE") <> 0 Then
wscript.echo strCurrentLine
Elseif InStr(strCurrentLine, "<DNS_NAME VALUE =") <> 0 Then
wscript.echo strCurrentLine
Elseif InStr(strCurrentLine, "USER_NAME =") <> 0 Then
wscript.echo strCurrentLine
Elseif InStr(strCurrentLine, "<PRIM_DNS_SERVER") <> 0 Then
wscript.echo strCurrentLine

End If



Loop
objFile.Close
 
this would be at its simplest

Dim RegEx : Set RegEx = New RegExp
RegEx.Pattern = Chr(34) & "(.+)" & Chr(34)
RegEx.IgnoreCase = True
RegEx.Global = True

Dim strTemp : strTemp = "<IP_ADDRESS VALUE = ""100.148.8.182""/>"
WScript.Echo RegEx.Execute(strTemp)(0).SubMatches(0)

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Awesome that works great!! Now where would be the best place for this in the script I have? At the bottom, as a function?
 
A function would be good, but you can place the RegEx definition before you Do Until objFile.AtEndOfStream loop

Then in the loop do something like

If RegEx.Test(strCurrentLine) Then
set colMatches = RegEx.Execute(strCurrentLine)
...the rest of your code
End If

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top