If I understand correctly, you want to find any line with the word "Skipped" followed by a line with the number 1 in the column below "Skipped", and append those two lines and the five preceding lines to a new file?
- Read LogFile.txt into an array
- Iterate through the array searching for lines with "Skipped"
- Whenever you find one, use a regex match to see if the next line (i.e., next element of the array) has a 1 in the corresponding position
- Use an array slice to get the elements from 5 preceding to 1 following the current one, and append it to the new file
The following will work if all the matching lines are formatted as in your example:
$logfile = gc '<path>\Logfile.txt'
for ($i = 0; $i -lt $logfile.count; $i++) {
if ($logfile[$i] -match 'Skipped') {
if ($logfile[$i + 1] -match '(?<=Dirs :(\s+[0-9]+){2}\s+)1') {
$logfile[($i - 5)..($i + 1)] | Out-File -Append '<path>\Logfile_Parsed.txt'
}
}
}
If the columns can vary in number and order, you'll need to use capture groups to find the ordinal position of "Skipped" and check if there is a 1 in the corresponding position on the next line. That's a little more complicated, so I won't get into that if this is sufficient.