Find/Replace text in file

Script to search and replace a string in a file, or all files in the directory 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:

search options
php search.php options

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:

search text file

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

search text *.html

And to include subdirectories:

search -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 parameter commands a substitution:

search -r oldstring newstring *.html

Changes in versions

Download