0

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

include("path/to/file.php");

I would like to change this line in every file to

require_once("path/to/file.php");

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
Gordonium
  • 101
  • 1
  • 2
  • 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

1 Answers1

2

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");".

heemayl
  • 54,820
  • 8
  • 124
  • 141