![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Parse Log files into a strongly type Object Fellow humans, I'm trying to process the following data from a log file into a strongly typed object for further analysis:- 05-Nov-06 12:00:06.287 ( -1 4360 4356) dual_flsrv.exe:dual_flsrv.c,v:267: connection accepted from client SVRPCSA address 158.89.5.16 05-Nov-06 12:00:06.287 ( -1 4360 8220) dual_flsrv.exe:rcv_u_fl.c,v:165: serving client SVRPCSA address 158.89.5.16 This is the script that I'm using to parse the data into an object:- switch -file c:\svrlog.txt -regex { "^\s*(\d\d-\w\w\w-\d\d)\s*(\d\d:\d\d:\d\d\.\d\d\d)\s*(.*[0-9]\))\s*(.*)" { $obj = New-Object -TypeName System.Management.Automation.PSObject $prop = New-Object System.Management.Automation.PSNoteProperty 'Date', $matches[1] $obj.PSObject.Properties.Add($prop) $prop = New-Object System.Management.Automation.PSNoteProperty 'Time', $matches[2] $obj.PSObject.Properties.Add($prop) $prop = New-Object System.Management.Automation.PSNoteProperty 'Code', $matches[3] $obj.PSObject.Properties.Add($prop) $prop = New-Object System.Management.Automation.PSNoteProperty 'Desc', $matches[4] $obj.PSObject.Properties.Add($prop) $obj } } The question is, how can I collect the output of the above script into a collection of an object for further analysis. e.g say sort on code and list. say like $x = switch -file c:\svrlog.txt -regex { .........} (which doesn't work.) Any idea's Many thanks in advance |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Parse Log files into a strongly type Object Please ignore as it's been answered below. The problem is I published via google groups, and that doesn't seem to work correctly. Which is strange for Google. ;-) "Karlos" wrote: > Fellow humans, > > I'm trying to process the following data from a log file into a > strongly typed object for further analysis:- > > 05-Nov-06 12:00:06.287 ( -1 4360 4356) > dual_flsrv.exe:dual_flsrv.c,v:267: connection accepted from client > SVRPCSA address 158.89.5.16 > 05-Nov-06 12:00:06.287 ( -1 4360 8220) > dual_flsrv.exe:rcv_u_fl.c,v:165: serving client SVRPCSA address > 158.89.5.16 > > This is the script that I'm using to parse the data into an object:- > > switch -file c:\svrlog.txt -regex { > > "^\s*(\d\d-\w\w\w-\d\d)\s*(\d\d:\d\d:\d\d\.\d\d\d)\s*(.*[0-9]\))\s*(.*)" > { > $obj = New-Object -TypeName System.Management.Automation.PSObject > $prop = New-Object System.Management.Automation.PSNoteProperty > 'Date', > $matches[1] > $obj.PSObject.Properties.Add($prop) > $prop = New-Object System.Management.Automation.PSNoteProperty > 'Time', > $matches[2] > $obj.PSObject.Properties.Add($prop) > $prop = New-Object System.Management.Automation.PSNoteProperty > 'Code', > $matches[3] > $obj.PSObject.Properties.Add($prop) > $prop = New-Object System.Management.Automation.PSNoteProperty > 'Desc', > $matches[4] > $obj.PSObject.Properties.Add($prop) > $obj > } > > } > The question is, how can I collect the output of the above script into > a collection of an object for further analysis. e.g say sort on code > and list. > > say like $x = switch -file c:\svrlog.txt -regex { .........} (which > doesn't work.) > > Any idea's > > Many thanks in advance > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| discovering the type of an object | PowerShell | |||
| parse files | VB Script | |||
| Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]' | .NET General | |||
| Parse XML files from Powershell? | PowerShell | |||
| Parse Log files into a strongly type Object | PowerShell | |||