I would like to write a script to convert svg files in a directory to png using svgexport cli
svgexport input.svg input.jpg
How can I use find and xargs -I {} to find and print out the svg files using the following:
find . -iname -0 "*.svg" | xargs -I {} svgexport {} ???
How can I fill-in the second argument by using the first argument and replacing .svg with .jpg?
xargs will run the first two commands in parallel, and then whenever one of them terminates, it will start another one, until the entire job is done. The same idea can be generalized to as many processors as you have handy. It also generalizes to other resources besides processors.
xargs (short for "extended arguments") is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.
xargs is a Unix command used to build and execute commands from the standard input. You can combine it with other powerful Unix commands, such as grep , awk , etc., by using pipes. In simple terms, it passes the output of a command as the input of another. It works on most Unix-like operating systems.
I think it's best to do this with a while
loop:
find . -iname "*.svg" -print0 |
while IFS= read -r -d '' file; do
svgexport "$file" "${file%.svg}.jpg"
do
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