![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Parsing log files for analysis 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: Parsing log files for analysis Please ignore as it's been answered below (many thanks). 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 | |||
| XML parsing and Win7 unattended answer files | PowerShell | |||
| Parsing AssemblyInfo files | .NET General | |||
| I am looking for information on parsing log files (text) | PowerShell | |||
| parsing csv files with fields that may contain commas | PowerShell | |||
| WMP Needs BPM Analysis | Vista music pictures video | |||