This question already has an answer here:

I have ~750 .php files in the same directory that contain the line


I would like to change this line in every file to


What would be an efficient method to do so? So far I have tried the following Sed command with no luck:

sed 's#include("path/to/file.php");#require_once("path/to/file.php");#' *.php

marked as duplicate by jasonwryan, Anthon, Networker, peterph, cuonglm Feb 24 '15 at 10:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Your command looks correct, but you need to add -i option to sed in order to change files in place. – jimmij Feb 23 '15 at 23:32

Try this:

find /path/to/the/directory -type f -exec sed -i 's/include\(.*\)/require_once\1/' {} +

This will find all the files in the given directory and replace the lines "include("path/to/file.php");" of each file to "require_once("path/to/file.php");".

Not the answer you're looking for? Browse other questions tagged or ask your own question.