У меня есть текстовый файл в следующем формате:
line1
line2
Notes:some text here
and also some text here
Path : a path
line3
line4
Notes:some text here
and also some text here
and some text here
Path : a path
line5
line6
Notes:
some text here
and also some text here
and some text here
Path : a path
Попытка удалить строку с примечаниями и удалить весь текст перед Path.Я хочу, чтобы вывод выглядел так:
line1
line2
Path : a path
line3
line4
Path : a path
line5
line6
Path : a path
itried below code:
$File = 'D:\test.txt'
$text = Get-Content -Path 'D:\test.txt'
$Pattern = '(?m)^Notes:[\r\n]+.*?[\r\n]Path[\r\n]'
$text -replace $Pattern, ' ' |
Out-File -FilePath $File -Force