Find/Replace text in file

Script to search and replace a string in files in a directory and sub-dirs.

They may be chosen according to a mask. The script is recursive and can perform search or replacement in all subdirectories.

It is a command line program with a binary and PHP executables, and a source code in Scriptol or C++.

Using the program

You can run the binary program or the script file with this commands:

If the source is compiled to a binary executable:

search [options] "text" 

Or compiled to PHP:

php search.php [options] "text"

Searching a string

To search a string in the contents of a file, go to the directory where the file is stored.

To search in a single file, type:

php search.php "text" file

In all files in the directory, use a mask, for example *. html

php search.php "text" *.html

And to include subdirectories:

php search.php -r "text" *.html

The other options are:

Replacing a string

The rules and options are the same, however there is an extra parameter that is the string that replaces the string found. The sole presence of this extra parameter commands a substitution:

php search.php "oldstring" "newstring" *.html

Changes in versions

Download