Reputation: 57
how merge same name's pdf files
poetry_2.pdf
poetry_3.pdf
poetry_4.pdf
metaphysics_2.pdf
metaphysics_3.pdf
i look for
poetry.pdf
metaphysics.pdf
failed this loop to check pdf files and merge with pfunite
for file1 in *_02.pdf ; do
# get your second_ files
file2=${file1/_02.pdf/_03.pdf}
# merge them together
pdfunite $file1 $file2 $file1.pdf
done
Upvotes: 0
Views: 187
Reputation: 27215
First, you need a list of prefixes (e.g. poetry
, metaphysics
). Then, iterate over that list and unite prefix_*.pdf
into prefix.pdf
.
Here we generate the list of prefixes by searching for files ending with _NUMBER.pdf
and removing that last part. This assumes that filenames do not contain linebreaks.
printf %s\\n *_*.pdf | sed -En 's/_[0-9]+\.pdf$//p' | sort -u |
while IFS= read -r prefix; do
pdfunite "$prefix"_*.pdf "$prefix.pdf"
done
Upvotes: 3