I'm new to Perl scripting, but I need to do a large amount of regex find-and-replaces across hundreds of files.
I came across this website which recommends the Perl command perl -p -i -e 's/oldstring/newstring/g' *
to get all files, and then perl -p -i -e 's/oldstring/newstring/g' 'find ./ -name *.html\'
to filter that to certain files.
My goal is to find all *.csproj and *.vbproj files and replace a reference to a .dll to a new path.
Those are both XML file types.
The text I'm replacing is
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
with
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
<HintPath>..\..\..\..\ExternalDLLs\log4net.dll</HintPath>
</Reference>
The command I have so far is
perl -p -i -e 's/<Reference Include="log4net, (?:.*?[\t\s\n\r])*?<\/Reference>/<Reference Include="log4net, Version=1\.2\.10\.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL"><SpecificVersion>False<\/SpecificVersion><Private>True<\/Private><HintPath>\.\.\\\.\.\\\.\.\\\.\.\\ExternalDLLs\\log4net\.dll<\/HintPath><\/Reference>/g' `find . -type f \( -name "*.vbproj" -or -name "*.csproj" \)`
Which seems to try and work, but it just ends up deleting all of my *.vbproj and *.csproj files.
I can't figure out why my script is deleting files.
Any help?
Edit: it prints this out per file
Can't do inplace edit on ./Middletier/TDevAccess/AmCad.Components.TDevAccess.csproj: No such file or directory.
Edit 2: Im using Bash on Ubuntu on Windows if that matters
Could this be related?