0

I'm using a tool that converts file types, but only works on one file at a time. I've put the URLs to these files into a text file, which I want to loop through with bash. The command then outputs files, but I want each file to be named uniquely. For example, output file one should be named output1.pdf, two should be output2.pdf, etc.

Here's what I have so far:

for i in `cat input.txt`; do
    converttopdf $i output.pdf
done

But that will simply overwrite output.pdf over and over. How can I make it output a unique file each time?

2
  • 1
    converttopdf $i $i.pdf so you'd get test.txt.pdf as output? Commented Jan 12, 2012 at 1:49
  • @Marc: I would, but the URLs are quite long, and I don't want the whole thing to be output. Commented Jan 12, 2012 at 1:59

2 Answers 2

2
num=0
while read -r; do
    ((num++))
    converttopdf "$REPLY" "output_${num}.pdf"
done < file_with_urls

keep a counter, and place in the output filename

Sign up to request clarification or add additional context in comments.

Comments

0

With a counter?

c=1
echo $c     # "1"
c=$(($c+1))
echo $c     # "2"

1 Comment

Can you explain how I can convert this to a usable file path? Can I just do converttopdf $i output$c.pdf? Or is there some way to place the variable inside the argument?

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.