#!/bin/bash #Get the folder with the pdf documents in it. #echo "" #echo "This will sort out the addresses in all the Statement PDF's into 2 folders so that you can then run the Merge file." #echo "To get started please answer 2 questions." #while : #do # echo -e "Where is the directory with ALL the pdf statments?" # read PDFDIR # if [ -d $PDFDIR ] # then # break # else # echo "Directory not found." # fi #done #Get the folder for the output file. #echo "" #while : #do # echo -e "What output directory do you want for the sorted pdf's? This will sort into 2 folders, Missing_Addresses and Address" # read OUTPUTFOLDER # if [ -d $OUTPUTFOLDER ] # then # break # else # echo "Directory not found." # fi #done #Create the csv and headers for the Addresses. It is tab separated. mkdir $OUTPUTFOLDER/Addresses touch $OUTPUTFOLDER/Addresses/Addresses.csv echo -e "File,User,Street,City,State,Zip" > $OUTPUTFOLDER/Addresses/Addresses.csv #Create csv with all the files with missing addresses mkdir $OUTPUTFOLDER/Missing_Addresses touch $OUTPUTFOLDER/Missing_Addresses/Missing_Addresses.csv echo -e "File\tUser" > $OUTPUTFOLDER/Missing_Addresses/Missing_Addresses.csv cd $PDFDIR #FOLDER=$(ls | grep *.pdf) #echo $FOLDER #*.pdf represensts All files in the current directory with a pdf extention. for f in $PDFDIR/* do echo "Processing file $f." #pdftotext converst the file to text and places it in the file name temp pdftotext "$f" - > TEMP #assigns the lines with relevant values to their variable USER=$(sed -n '12p' TEMP) ADDRESS1=$(sed -n '13p' TEMP) ADDRESS2=$(sed -n '14p' TEMP) echo -e "User is $USER" echo -e "Address is $ADDRESS1 $ADDRESS2" if [ -z "$ADDRESS1" ] then #Move the file with the Missing addresses to the Missing Address folder and make an note in its csv. echo "Copying file to the folder called Missing_Addresses" cp "$f" "$OUTPUTFOLDER"/Missing_Addresses/ echo -e "$f\t$USER" >> "$OUTPUTFOLDER"/Missing_Addresses/Missing_Addresses.csv #Adds the row of variables to the csv. >> appends to the file. \t represents tabs else # Split Addresses CITY=$(echo $ADDRESS2 | cut -d, -f1) ADDRESS2=$(echo $ADDRESS2 | sed -e "s/$CITY, //") STATE=$(echo $ADDRESS2 | cut -d" " -f1) ZIP=$(echo $ADDRESS2 | cut -d" " -f2) echo -e "$f,$USER,$ADDRESS1,$CITY,$STATE,$ZIP" >> $OUTPUTFOLDER/Addresses/Addresses.csv cp "$f" $OUTPUTFOLDER/Addresses/ echo "Copying file to the folder called Addresses" fi done echo "All Done!" You can find all the Files in $OUTPUTFOLDER!" echo " " echo " " exit