I'm trying to come up with a sed script to modify the constructors in a couple hundred php files from php4 style to php5 style. I'm making some progress, but I'm having a problem with getting the back references out of sed. Here is an example file :
<?php
class Dashboard extends CI_Controller {
function Dashboard()
{
parent::Controller();
}
}
The goal is to grab the class name from the first line (which will have 0 or 1 blank lines between it and the
This works as expected:
sed -En '/^class\ ([a-zA-Z0-9]+)/ {
n;H;x;n;H;x;'s/Dash/Derp/';P
}' dashtest.php
Giving the output:
function Derpboard()
But why is this not replacing Dashboard with __construct?:
sed -En '/^class\ ([a-zA-Z0-9]+)/ {
n;H;x;n;H;x;'s/\1/__construct/';P
}' dashtest.php
Any other advice on this would be welcome. My intention is to wrap this in a shell script that is making a bunch of other changes migrating from an ancient version of codeIgnitor php framework the current version.