This question already has an answer here:
My qeustion is how in BASH I can change one word in many txt files in one directory and few subdirectories? I did as below (check all similar topics) but it is still not working. changePhrase is a name of directory where the subdirectories and files are. Inside that files is a string that I want to change. I have to make it with a for loop (it's a task). Where is mistake? Thank you.
#!/bin/bash
for file in changePhrase; do
if [[ -f $file ]] && [[ -w $file ]]; then
sed -i -- 's/old/new/g' "$file"
fi
done
If changePhrase is the name of your directory try to append
/**{,/*}
to it. Using the globbing will make the loop go over all the files.I think your code will work if you just add find to the for loop so:
you can do
-type f
-> file-a
-> and-writable
-> your-w