Over a million developers have joined DZone.

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

·
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.
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}