#!/bin/bash #get directory for pdf files #get output directory for files #Get the folder with the pdf documents in it. while : do echo -e "What is the directory with the pdfs?" read PDFDIR #PDFDIR="/home/btmccrea/Downloads/pdfs" if [ -d $PDFDIR ] then break else echo -e "Directory not found." fi done #Get the folder for the output file. while : do echo -e "What is the output directory for the pdf's with missing addresses?" read OUTPUTFOLDER #OUTPUTFOLDER="/home/btmccrea/Downloads/output" if [ -d $OUTPUTFOLDER ] then break else echo -e "Directory not found." fi done cd $PDFDIR for FILENAME in $PDFDIR/* do echo $FILENAME #The next Line assigns the number of pages to the value LOCATION to be used for were the file goes LOCATION=$(pdfinfo "$FILENAME" | grep Pages: | awk '{print $2}') #Test if the file exists and if it does move it to Temp.pdf to be merged back to its original location. if test -f $OUTPUTFOLDERStatement-Pages-$LOCATION.pdf then mv $OUTPUTFOLDERStatement-Pages-$LOCATION.pdf $OUTPUTFOLDERtemp.pdf pdfunite "$FILENAME" $OUTPUTFOLDERtemp.pdf $OUTPUTFOLDERStatement-Pages-$LOCATION.pdf else #IF the file doesn't exist create the file with the merge. pdfunite "$FILENAME" $OUTPUTFOLDERStatement-Pages-$LOCATION.pdf fi done exit