Given a text file I want to replace all the text (across multiple lines) between two given words.
Text file example:
line1 line2 XstartX line4 XendX line5
if I wanted to replace all the text between start and end with YYY
the resulting file should be
line1 line2 XstartYYYendX line5
I tried
$file='C:\Path\to\file.txt'
$raw = Get-Content $file -Raw
$raw -ireplace '(?<=start).+?(?=end)', 'YYY'
$raw | Set-Content $file
but... no luck!