I am trying to write a bash script to merge all pdf files of a directory into one single pdf file. The command pdfunite *.pdf output.pdf
successfully achieves this but it merges the input documents in a regular order:
1.pdf
10.pdf
11.pdf
2.pdf
3.pdf
4.pdf
5.pdf
6.pdf
7.pdf
8.pdf
9.pdf
while I'd like the documents to be merged in a numerical order:
1.pdf
2.pdf
3.pdf
4.pdf
5.pdf
6.pdf
7.pdf
8.pdf
9.pdf
10.pdf
11.pdf
I guess a command mixing ls -v
or sort -n
and pdfunite
would do the trick but I don't know how to combine them.
Any idea on how I could merge pdf files with a numerical sort?