Parse custom log by date

Hi All thanks for your help

I was capturing lines by date, however the logs have change to contain additional information on the subsequent lines. I need a method to still parse by date but capture the lines after the date entry as well.

Here is an example of the log entries

2021-05-18T21:05:40.776Z error some data
 More error information
2021-05-18T21:05:41.776Z error some data
 More error information
 More error information
 More error information
2021-05-18T21:05:42.776Z error some data
 More error information
type or paste code here

Here is my code I was using when all data was on same line as the date/time

$Log1=gc $mylogs |  ? {
    $g = [regex]::Match($_, '(\d\d\d\d)-(\d\d)-(\d\d)').Groups
    (Get-Date -Year $g[1].Value -Month $g[2].Value -Day $g[3].Value) -ge $start }

You could use Select-String to identify all the lines with the date and time information. Then you could parse this collection of line numbers to assign the subsequent lines to the according date/time line.

This post has a very similar discussion and solutions that may help you.

1 Like