Bash: any command to replace strings in text files?
Use sed
in combination with find
. For instance:
find . -name "*.txt" | xargs sed -i s/Coke/Pepsi/g
or
find . -name "*.txt" -exec sed -i s/Coke/Pepsi/g {} \;
(See the man page on find for more information)
Combine sed with find like this:
find . -name "file.*" -exec sed -i 's/Coke/Pepsi/g' {} \;
IMO, the tool with the easiest usage for this task is rpl
:
rpl -R Coke Pepsi .
(-R
is for recursive replacement in all subdirectories)