test.bash 697 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. # caclurate the page counts of the two files
  3. pagesA=$(pdftk abclager1.pdf dump_data | awk '/NumberOfPages/ {print $2}')
  4. pagesB=$(pdftk abclager2_rev.pdf dump_data | awk '/NumberOfPages/ {print $2}')
  5. # determine which file has more pages
  6. if (( pagesA < pagesB )); then
  7. min=$pagesA
  8. max=$pagesB
  9. remainder="B"
  10. else
  11. min=$pagesB
  12. max=$pagesA
  13. remainder="A"
  14. fi
  15. # generate a list of pages up to the common last page
  16. for (( i = 1; i <= min; i++ )); do
  17. pages+=(A"$i" B"$i")
  18. done
  19. # append a list of remaining pages
  20. for (( i = min+1; i <= max; i++ )); do
  21. pages+=("$remainder$i")
  22. done
  23. pdftk A=abclager1.pdf B=abclager2_rev.pdf cat "${pages[@]}" output output.pdf