Does anyone know how to find and replace text inside a file with Phing?
Find and replace text within a file using sed command Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input.txt. The s is the substitute command of sed for find and replace. It tells sed to find all occurrences of 'old-text' and replace with 'new-text' in a file named input.txt.
If you don't want to copy files and just replace a string in the current folder where your files reside, do a reflexive task:
<reflexive>
<fileset dir=".">
<include pattern="*.js" />
</fileset>
<filterchain>
<replaceregexp>
<regexp pattern="SEARCH" replace="REPLACEMENT"/>
</replaceregexp>
</filterchain>
</reflexive>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With