I want to run a script in a directory in order to generate an svg file for each found dot file. Something like:
find . -name "*.dot" -exec dot -Tsvg \{} \;
This works fine but just output the result on stdout. usually I am using a redirection to generate the svg file. How can I get the dot file name to use it in the redirection like
find . -name "*.dot" -exec dot -Tsvg > "$dotfilename".svg \{} \;
The following:
for i in `find . -name "*.dot"`; do
dot -Tsvg $i > $i.svg
done
performs the find (in backticks) and loops over the results, executing dot
for each one. The filename is in $i
.
This uses backtick substitution and is a useful mechanism for capturing command output for subsequent use in another command.
To remove the extension and add another, use ${i%.*}.svg
. See this SO answer for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With