I need to write a script that replaces all the occurrences of a certain string to "replaceWithThisNewString" in all the files in a directory and all its sub directories. How can it be done?
3 Answers
try this line:
find /aDir -type f |xargs sed -i 's/certainString/replaceWithThisNewString/g'
1 Comment
Wrikken
Ḧm, if going the
xargs route, I'd use find .... -print0 | xargs -0 ... just to be safe.Using bash4 :
shopt -s globstar # if not already enabled
sed -i '/certainString/s/certainString/replaceWithThisNewString/g' **