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

Regular Expression Help 1

Status
Not open for further replies.
Oct 9, 2003
174
0
0
US
I am writing a script that will read each line of a log file and pull out the user name string. The log file is populated with lines like this:

11.111.247.148 - (CN=Blow\\, Joe,CN=Users,DC=CompanyX,DC=com)@(LDAP) [06/May/2008:08:33:23 -0400] "GET 11.111.247.148 - - [06/May/2008:08:33:24 -0400] "GET /exchweb/6.5.7651.60/controls/blank.htm
111.111.247.148 - (CN=TheTank\\, Frank,CN=Users,DC=CompanyAB,DC=com)@(LDAP) [06/May/2008:08:33:25 -0400] "GET HTTP/1.1"
11.11.148.211 - (CN=BeanStalk\\, Jacknda,CN=Users,DC=CompanyFF,DC=com)@(LDAP) [06/May/2008:08:33:25 -0400] "GET
What would be the regular expression to pull the user name string from the line? For example, from the first line I am looking to pull only (CN=Blow\\, Joe,CN=Users,DC=CompanyX,DC=com).

Also some of the lines as you can see do not have any username assosiated with them. I need to just disregard those lines. Those lines start with a [ instead of a ( though after the ip.

Thanks in advance.
 
This is the code that I have. I am just trying to figure out what the reg expression pattern is. I have tried a couple combinations with limited success.

dim s, t, rx, cm, m

set rx=new regexp
with rx
.global=false
.pattern=\(*\)
end with

Const ForReading = 1

Set objFSo = CreateObject("Scripting.FileSystemObject")

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='D:\SCRIPTING\Aventail\ExtraWeb\working'} Where " _
& "ResultClass = CIM_DataFile")

For Each objFileName In colFileList
strName = objFileName.FileName

Set objFile = objFSO.OpenTextFile(objFileName.Name, ForReading)

Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("D:\SCRIPTING\Aventail\ExtraWeb\working\tmp.txt", 8, True)


Do Until objFile.AtEndOfStream
s = objFile.ReadLine

if rx.test(s) then
set cm=rx.execute(s)
for each m in cm
't: output
t= m.submatches(0)
'write the t to the output file


file.Write t & ";"


next
set cm=nothing
end if

file.Write vbCrLf
Loop

file.Close


objFile.Close

Next
 
This may help you along...

Code:
Option Explicit

Dim arrLines : arrLines = Array("11.111.247.148 - (CN=Blow\\, Joe,CN=Users,DC=CompanyX,DC=com)@(LDAP) [06/May/2008:08:33:23 -0400] ""GET [URL unfurl="true"]http://exchweb/6.5.7651.60/controls/ctrl_message.htc""",[/URL] _
"11.111.247.148 - - [06/May/2008:08:33:24 -0400] ""GET /exchweb/6.5.7651.60/controls/blank.htm""", _
"111.111.247.148 - (CN=TheTank\\, Frank,CN=Users,DC=CompanyAB,DC=com)@(LDAP) [06/May/2008:08:33:25 -0400] ""GET [URL unfurl="true"]http://exchweb/img/print.gif[/URL] HTTP/1.1""", _
"11.11.148.211 - (CN=BeanStalk\\, Jacknda,CN=Users,DC=CompanyFF,DC=com)@(LDAP) [06/May/2008:08:33:25 -0400] ""GET [URL unfurl="true"]http://exchweb/img/spelling.gif""")[/URL]

Dim RegEx : Set RegEx = New RegExp
RegEx.Pattern = "\((CN=.*)\)@"
RegEx.IgnoreCase = True
RegEx.Global = True

Dim strLine
For Each strLine In arrLines
	If RegEx.Test(strLine) Then
		WScript.Echo RegEx.Execute(strLine)(0).SubMatches(0)
	End If	
Next

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

Part and Inventory Search

Sponsor

Back
Top