DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Shell Script To Recursively Find Files With The Same Name And Replace Text Within Each Of Them

11.21.2007
| 8895 views |
  • submit to reddit
        This shell script recursively finds files with the same name and replaces text within each of them

FILE="filename.txt"
FIND="old text"
REPLACE="new text"
find . -name $FILE -print0 | xargs -0p perl -pi -w -e "s/$FIND/$REPLACE/g;"

Remove the p flag if confirmation is not necessary.