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:
- -i : ignore uppercases
- -c : search for an identifier inside source code
- -v : display each scanned file
- -q : quiet, display nothing.
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
-
Version 1.4
The -v option replaces the -f option.
The processing of command line options has been improved. - Version 1.3
The -r recursive option has been added.
When this options is enabled, filenames are shown with the path.

