I have such a need:
In the directory video, I need to
find ./video -type f | while read myfile; do
tmp=`basename $myfile` #example.mp4
tmp="${tmp/.mp4/.html}" #example.html
cp index.html "$tmp"
sed -i '' "s#sceneFilePath:.*#sceneFilePath: \"$myfile\",#g" $tmp
#done;
Here is my directory:
dir
|--- video
| |--- example.mp4
|--- index.html
|--- generateHtml.sh
generateHtml.sh is just like above.
Here is what it does:
find the example.mp4 file in video, then cp index.html example.html and change a string in the example.html.
It works well.
But now for some path and name of .mp4 files, there are some special characters, such as &, , -. It doesn't seem that while read works for these cases.
I've heard that find -exec can handle all of special characters but I don't know how to use it for this case.
find.jqrather than hackery withsed. You're going to have a bad time here if any names need to be escaped or quoted to be valid inside your HTML file.