I have a log file with entries like
AA this is a line A
CODE C
CODE C
CODE C
AA this is a line A
CODE C
AA this is a line A
CODE C
CODE C
AA this is a line A
So I need to find the first
AA this is a line A
and grab then all corresponding CODE C below and then ideally another object with AA this is a line A and the next CODE C until the whole file is done
I have:
$codelog = 'C:\data\code.log'
$collection = get-content $codelog
$endline = Get-Content $codelog | Measure-Object -Line | Select -ExpandProperty Lines
$i = 0
$withlines = get-content $codelog | foreach{"$i $_";$i++}
$linenumbers = @()
foreach($line in $withlines)
{
if($line -like "AA This is a line*")
{$linematch = $line.split(' ')[0];$linenumbers += $linematch}
}
$totallines = $linenumbers | Measure-Object -Line | select -ExpandProperty lines
$linereader = @()
$linereader = 1
foreach($code in $linenumbers)
{
}
I can't get my head around