Avin Verma
Avin Verma

Reputation: 21

How to copy a substring from a text file using powershell

$result = Get-Content -Path D:\out.txt  
$grepString = $result | Select-String -Pattern "startpoint of the string"    
Write-Host $grepString

I used this code but it is printing only one line(when it get \n), But I want my output in containing rest of the lines

Upvotes: 0

Views: 459

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174900

You could use the .Where() extension method in SkipUntil mode:

$result = Get-Content -Path D:\out.txt  
$filteredResults = $result.Where({$_ -match "startpoint of the string"}, 'SkipUntil')

$filteredResults is now an list of the input strings from the first match till the end.

Upvotes: 1

Related Questions