Reputation: 6305
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?
Upvotes: 0
Views: 127
Reputation: 185095
Using bash4 :
shopt -s globstar # if not already enabled
sed -i '/certainString/s/certainString/replaceWithThisNewString/g' **
Upvotes: 0
Reputation: 70470
find /path/to/dir -type f -exec sed -i 's/original/replacement/g' {} \+
Or if your find
doesn't support \+
:
find /path/to/dir -type f -exec sed -i 's/original/replacement/g' {} \;
Upvotes: 3
Reputation: 195059
try this line:
find /aDir -type f |xargs sed -i 's/certainString/replaceWithThisNewString/g'
Upvotes: 0