0

I have no previous experience with writing a unix script but what I want seems like a simple task.. I want to run this command for all the pdf files in a folder

pdf2txt.py -o naacl06-shinyama.html samples/naacl06-shinyama.pdf

if there is a file called anypdf.pdf the command would look like:

pdf2txt.py -o anypdf.html samples/anypdf.pdf

so if my folder includes 3 pdf files like, abc.pdf aaa.pdf bbb.pdf I want to end up with abc.html aaa.html and bbb.html

thanks in advance

1 Answer 1

1
for pdf in samples/*.pdf; do
    html=$(basename "$pdf" .pdf).html
    pdf2txt.py -o "$html" "$pdf"
done

If you don't have basename then try this alternative, which uses bash's ## and % constructs to do replacements inline.

#!/bin/bash

for pdf in samples/*.pdf; do
    html=${pdf##*/};
    html=${html%.pdf}.html
    pdf2txt.py -o "$html" "$pdf"
done
Sign up to request clarification or add additional context in comments.

2 Comments

thanks but I getting a (i believe) a python error like TypeError: __init__() got an unexpected keyword argument 'outdir'
@GorkemYurtseven Check that it's running pdf2txt.py with the correct arguments. That error's coming from Python, not from the shell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.