Powershell Select-String -context

1.1k views Asked by At

I have a text file that i need to read the lines in between a pattern and include the pattern match.

Example:

Attributes
att 1
att 2
col 1
col 2

Attributes
att 1
att 2
pos 1

Attributes
set 1
set 2
att 1

Right now I have:

$Attributes = Get-Content att.txt | Select-String "Attributes" -Context 0,3

Which returns the attributes and the next 3 lines into an array entry. However, I would like this to be dynamic and not specifically the next 3 lines. I would like all lines until the next attributes pattern.

0

There are 0 answers