The Blog

Keep up to date with the latest developments at Burren Web Design.

Using sed to do fast find/replace

2017-07-18 13:30:15

I recently upgraded my Website Workshop and moved from PHP 5.3 to PHP 7.1 - This presented a problem since all my mysql commands were written in the old format (e.g. myql_query etc) while these commands are deprecated in the new version and only (e.g. mysqli_query etc) are used.. To compound the issue the hosting service is still using PHP 5.3 - To overcome this problem I created a new file with online and offline elements and a list of functions in the form (e.g. mysqlquery etc) with definitions for the old and new versions of PHP. I then had to simply rename all my existing function calls (e.g. mysql_query -> mysqlquery). To do this quickly and easily I used the very powerful UNIX command called sed (stream editor). The following simple command replaced all instances of mysql_with mysql in a website folder in less than a second...

sed -i s/mysql_/mysql/g `find /var/www/html/workingwebsite/ -type f -name *.php`

Nifty Stuff!!!


More From the Blog...

Back to Blog...

About...

Burren Web Design is a unique IT and Design company providing tailor-made Web Design and IT Solutions for Business and Residential Customers in County Clare and beyond. No Job too Big or Small... read more

Social Media

Terms & Conditions

Click here for full Terms and Conditions.