Replace String in Unix

To replace all instances of a string in a directory (subdirectories included) do:
perl -e "s/FIND/REPLACE/g;" $(find path/to/DIRECTORY -type f)

The above will make a backup temp file of your original 
If you do not want a temp file with the .save extension then do:

perl -e "s/FIND/REPLACE/g;" -pi $(find path/to/DIRECTORY -type f)
You want to replace all instances of the word "design" with "dezine" in the directory /public_html/company/info

you can execute the command from document root as 
perl -e "s/design/dezine/g;" $(find public_html/company/info -type f)
or you can execute the command from public_html/company/ (a directory above) as:
perl -e "s/design/dezine/g;" $(find info -type f)

The above commands will search all files (.gif, .jpg, .htm, .html, .txt) so you might see some error messages "Can't open *.gif", etc)


To search just files of type, .htm without a backup file in the current directory only (no subdirectories) you could use:

perl -pi -e 's/design/dezine/g' *.htm
Taken from:


Popular posts from this blog

HIVE: Both Left and Right Aliases Encountered in Join

Assign select result to variable in Netezza stored procedure

Splitting value in Netezza using array_split