# Parse custom log by date

**URL:** <https://forums.powershell.org/t/parse-custom-log-by-date/16613>\
**Category:** PowerShell Help\
**Created:** [May 21, 2021, 7:32pm UTC](https://forums.powershell.org/t/parse-custom-log-by-date/16613 "2021-05-21T19:32:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![logan](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@logan](https://forums.powershell.org/u/logan)\
**Post date:** [May 21, 2021, 7:32pm UTC](https://forums.powershell.org/t/parse-custom-log-by-date/16613/1 "2021-05-21T19:32:00Z")

</div>

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

```auto
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

```auto
$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 }

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [May 21, 2021, 8:43pm UTC](https://forums.powershell.org/t/parse-custom-log-by-date/16613/2 "2021-05-21T20:43:59Z")

</div>

> [@logan](#):
>
> the logs have change to contain additional information on the subsequent lines.

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.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [May 21, 2021, 9:35pm UTC](https://forums.powershell.org/t/parse-custom-log-by-date/16613/3 "2021-05-21T21:35:22Z")

</div>

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

> [@Powershell String operation](https://forums.powershell.org/t/powershell-string-operation/16271/):
>
> Hi, I’m in a tricky situation to analyze a text output. My requirement is search a string and get a lines between them. For example, the following lines in a text file Filename1.log Data1 Data2 Data3 Filename2.log Data4 Data5 Data6 Data7 Filename3.log Data8 Data9 Data10 it goes several files as the output varies output I expect Filename1.log has 3 lines Filename2.log has 4 lines Filename3.log has 3 lines Please let me know if anyone can provide help, couldn’t get through surf…

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:24pm UTC](https://forums.powershell.org/t/parse-custom-log-by-date/16613/4 "2024-05-16T20:24:30Z")

</div>

Closed on May 16, 2024, 8:24pm UTC


