Reputation: 1214
I have a regex that searches a file and returns matches. It works fine, except it also gives me the filename and line number which I don't want. I know I can eliminate that by using the Line property of the matches in general. But I am using the context param to get lines below the match and I can't seem to get it to work with that using the Context property or line property:
select-string -Path $input_path -Pattern $regex -AllMatches -context 0,7
Upvotes: 0
Views: 60
Reputation: 201652
Try this:
Select-String -Path $input_path -Pattern $regex -AllMatches -Context 0,7 |
Foreach {"> $($_.Line)";$_.Context.PostContext}
If you needed PreContext, use the $_.Context.PreContext
property.
Upvotes: 1