0

When using find, how can I drop the original filename extension (i.e. .pdf) from the second pair of -exec braces ({})?


For example:

find ~/Documents -regex 'LOGIC.*\.pdf' -exec pdf2svg {} {}.svg \;

Input filename:

~/Documents/LOGIC-P_OR_Q.pdf

Output filename:

~/Documents/LOGIC-P_OR_Q.pdf.svg

Desired filename:

~/Documents/LOGIC-P_OR_Q.svg

  • 1
    It would be better to use -name "LOGIC*.pdf" to match the filename as -regex matches against the full pathname. – Kusalananda Jun 29 '18 at 13:00
4

You can use an "in-line" shell script, and parameter expansion:

-exec sh -c 'pdf2svg "$1" "${1%.pdf}.svg"' sh {} \;

or (more efficiently, if your find supports it)

-exec sh -c 'for f; do pdf2svg "$f" "${f%.pdf}.svg"; done' sh {} +
-1

One method would be to run the results through a basic script -

for i in $( find ~/Documents -regex 'LOGIC.*\.pdf' )  
do  
    o=$( echo $i | sed -e s/.pdf$// )  
    pdf2svg $i ${o}.svg  
done 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.