#!/bin/bash #get directory for pdf files #get output directory for files #Get the folder with the pdf documents in it. #echo "This will take the PDF statements that have been sorted and will merge them into PDF files based on the numbers of pages in the statement." #echo "" #echo "Before we begin we need a little information." #echo "" #while : #do # echo "Where is the directory that has the PDF statments with address?" # read PDFDIR # if [ -d $PDFDIR ] # then # break # else # echo "Directory not found." # fi #done #Get the folder for the output file. #while : #do # echo "" # echo "What output directory do you want for the sorted PDF's?" # read OUTPUTFOLDER # #OUTPUTFOLDER="/home/btmccrea/Downloads/output" # if [ -d $OUTPUTFOLDER ] # then # break # else # echo "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 $OUTPUTFOLDER/Statement-Pages-$LOCATION.pdf then mv $OUTPUTFOLDER/Statement-Pages-$LOCATION.pdf $OUTPUTFOLDER/temp.pdf pdfunite "$FILENAME" $OUTPUTFOLDER/temp.pdf $OUTPUTFOLDER/Statement-Pages-$LOCATION.pdf else #IF the file doesn't exist create the file with the merge. pdfunite "$FILENAME" $OUTPUTFOLDER/Statement-Pages-$LOCATION.pdf fi done echo "" echo "" echo "All done, you can find the PDF statments at $OUTPUTFOLDER. echo "" echo "" exit