I've been trying to replace a pattern of lines from multiple .xml files using Powershell scripts
For some reason, I still couldn't figure out how to do that even for a single file, this is what I've been using
$loc = file
$file = Get-Content $loc -Raw
$file -replace "(\<!-- First.*?\/>)","blank"
And these are the lines that I want to replace
<!-- First -->
<prop classproperty="1"
packageproperty="1.2"
/>
Basically I've been trying to use -Raw
property for the Powershell read into a single line and the tried to replace using the regex expression (\<!-- Weather.*?\/>)
. I want to replace from the commentary to the prop
tag closure. But every time I run my script, it changes nothing. What am I doing wrong? I ran this regex code, with the file on a single line using the https://regexr.com/ and it works perfectly
Also how can I apply the same change for multiple files? I tried to this, but it returns an error telling me that I don't have permission to the path
$loc = Get-Location
Get-ChildItem -Path $loc\*.* -Filter '*_property.xml' -Recurse | ForEach-Object {
(Get-Content -path $loc -Raw) -replace '(\<!-- Weather.*?\/>)','white'
}
Thanks!