Windows – Linux – Mac OSX Guides

Find & replace text within multiple files in a folder recursively in MacOSX

Today I looked at my old project codes and find out that I’ve put a lot of hard-code value, but couldn’t remember in which files the value is hard-code. So, instead of opening each file for investigation, “find” and “grep” comes to my rescue to be the best method of finding those hard-coded value.

Just go to the folder in which you want to search for, then use find & grep

$find . -type f -exec grep “<search_string_here>” {} \; -print

So how about replace those hard-coded value with another one? Well, you can try this on

– Go to the folder in which you want to start find & replace
– Enter at the command terminal

$perl -e “s/SEARCH_STRING/REPLACE_STRING/g;” -pi $(find . -type f)

The command will find in the current folder & subfolders for SEARCH_STRING and replace them with REPLACE_STRING.

Related Articles

Loading Facebook Comments ...

Post your comments

Your email address will not be published. Required fields are marked *