I had interesting task:
* I had to rename all shtml files into php
* Make all of shtml includes (<!--#include virtual="/file.shtml"-->) into php includes (<?php include("/file.php");?>)
On Linux operated server it went something like this (all recursive):
1.find . -name '*.shtml' | sed 's/\(.*\)\.shtml/mv \1.shtml \1.php/'|sh
Rename all .shtml files into .php
find . -name '*.shtml' finds all files named .shtml
sed 's/\(.*\)\.shtml/mv \1.shtml \1.php/' sed edits list of files where s tells to replace string (*.shtml) by another (mv \1.shtml \1.php), mv is command that really does renaming while 1 takes the name of the file in the first string and puts it there
| sh takes sed output and executes it
2.find . -type f | xargs sed -i 's/.shtml/.php/g'
Replaces .shtml within a text into .php, hence <!--#include virtual="/file.shtml"-->) becomes <!--#include virtual="/file.php"-->)
3.find . -type f | xargs sed -i 's/<\!--#include virtual=\"/<?php include(\"\\//g'
Similar as above making <!--#include virtual="/file.php"--> into <?php include("/file.php"-->
4.find . -type f | xargs sed -i 's/\.php\"-->/\.php\");\?>/g'
And finally I had <?php include("/file.php");?>
* Of course, I could optimize perl regex and make it into two steps, but this was 'faster' and safer to me.