I'm trying to extract a set of data from some (large) text files. Basically, each line looks something like this:
2011-12-09 18:20:55, ABC.EXE[3b78], The rest of the line...
I'd like to get the date and the bit between the braces (the process id), and then compile a table. The second stage of the task is to group this table so that I get the earliest date for each process id, in effect giving me the date and time of the first log entry per process id which will hopefully approximate to the start time of that instance of the process.
What I've got so far (split onto different line for readability)
gci -filter *.log -r
| select-string '(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}), ABC.EXE\[(.{4})'
| % { $_.matches } | % { $_.groups } | % { $_.value }
spits out the the captures. I'd like to ignore the first capture, and combine the second and third onto the same line.
Help? Please?
Edit: DOH! Can't answer my own question. So...
Ok, I think I'm on the right track. A SO question here helped me to get the individual parts I wanted, namely:
$_.matches[0].groups[1].value, $_.matches[0].groups[2].value
Then, an MSDN article here shows how to 'clump' the bits into an object, which allows it to be grouped / sorted / manipulated. Final result
gci -filter *.log | select-string '(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}), ABC.EXE\[(.{4})'
| % { new-object object
| add-member NoteProperty Name $_.matches[0].groups[1].value -passthru
| add-member NoteProperty PId $_.matches[0].groups[2].value -passthru }
Quite messy, so if anyone knows of a cleaner way to do it, please let me know.