I wrote a simple bash script as I need to split multiple pdfs into 2 pdfs on a regular basis. I need them to be split in the same sequence each time (pages 1-5 and 6 to last page). I need the newly split pdfs to be named uniquely so I can keep them apart (i.e. inv-1.pdf rec-1.pdf; inv-2.pdf rec-2.pdf, etc). My script only splits the 1 pdf when I have 5+ in the folder. Any suggestions are appreciated.
#!/bin/bash
for file in $(ls REQ*.pdf)
do
qpdf ${file} --pages . 1-5 -- inv-%d.pdf |\
qpdf ${file} --pages . 6-z -- rec-%d.pdf |\
echo >> ${file}
done
'''
Quick solution: Append
| xargs echo
to yourls
command.Rationale: In your case,
ls
output is one filename per line. Yourfor
loop picks up the filename in the same line only. The rest get ignored. You can read more aboutls
output behavior on this answer- What is the magic separator between filenames in ls output?The pipe (
|
) redirectsls
output toxargs
which appliesecho
to generate space-separated file names on a single line. Read more aboutxargs
on the man page