简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM