Search code examples
bashpastepdftk

Combing PDF's using pdftk and paste command to match file names


Trying to write a simple script for combining PDF's with similar names

Script so far

f1=filesa.txt
f2=filesb.txt
paste $f1 $f2
pdftk $f1 $2 output "$f1"_combined.pdf

Paste command output these correctly into two data columns

A001.pdf    A001_T.pdf
A0002.pdf   A0002_T.pdf
A03.pdf A03_T.pdf
A0004.pdf   A0004_T.pdf

The outcome that I'm looking for is to combine the PDF's with similar names into a new file with "_combined" at the end

I'm missing a logical step to put this files into a while read or something?


Solution

  • I could find a one-liner solution:

    paste filesa.txt filesb.txt | while read -r fileA fileB; do pdftk $fileA $fileB output ${fileA%.*}_combined.pdf; done
    

    You need to iterate over the result of paste, which I did with the while loop.