diff --git a/Find_Missing_Addresses.sh b/Find_Missing_Addresses.sh index cf307a1..65b9420 100755 --- a/Find_Missing_Addresses.sh +++ b/Find_Missing_Addresses.sh @@ -4,9 +4,10 @@ while : do echo -e "What is the directory with the pdfs?" - read PDFDIR - #PDFDIR=/home/btmccrea/Downloads/pdfs/ - if [ -d $PDFDIR ]; then + #read PDFDIR + PDFDIR="/home/btmccrea/Downloads/pdfs" + if [ -d $PDFDIR ] + then break else echo -e "Directory not found." @@ -16,9 +17,10 @@ done while : do echo -e "What is the output directory for the pdf's with missing addresses?" - read OUTPUTFOLDER - #OUTPUTFOLDER=/home/btmccrea/Documents/output/ - if [ -d $PDFDIR ]; then + #read OUTPUTFOLDER + OUTPUTFOLDER="/home/btmccrea/Downloads/output" + if [ -d $OUTPUTFOLDER ] + then break else echo -e "Directory not found." @@ -26,24 +28,43 @@ do done #Create the csv and headers for the Addresses. It is tab separated. -touch "$OUTPUTFOLDER"Addresses.csv -echo -e "File\tUser\tAddress" > "$OUTPUTFOLDER"Addresses.csv -#FILES=$(ls $PDFDIR) +mkdir $OUTPUTFOLDER/Non_Blank +touch $OUTPUTFOLDER/Non_Blank/Addresses.csv +echo -e "File\tUser\tAddress" > $OUTPUTFOLDER/Non_Blank/kkAddresses.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 -#echo $FILES +#FOLDER=$(ls | grep *.pdf) +echo $FOLDER #*.pdf represensts All files in the current directory with a pdf extention. -for f in *.pdf ; - do - #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 '13p' temp) - ADDRESS1=$(sed -n '14p' temp) - ADDRESS2=$(sed -n '15p' temp) - #Adds the row of variables to the csv. >> appends to the file. \t represents tabs - echo -e "$f\t$USER\t$ADDRESS1 $ADDRESS2" >> "$OUTPUTFOLDER"Addresses.csv - done +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 + #cat TEMP + #assigns the lines with relevant values to their variable + USER=$(sed -n '10p' TEMP) + ADDRESS1=$(sed -n '11p' TEMP) + ADDRESS2=$(sed -n '12p' 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 -e "Copying file to 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 + echo -e "$f\t$USER\t$ADDRESS1 $ADDRESS2" >> $OUTPUTFOLDER/Non_Blank/Addresses.csv + cp "$f" $OUTPUTFOLDER/Non_Blank/ + echo -e "Copying file to Non_Blank" + fi +done exit - - - diff --git a/Removing_Files.sh b/Removing_Files.sh old mode 100644 new mode 100755 index 9619424..c1c44bb --- a/Removing_Files.sh +++ b/Removing_Files.sh @@ -1,19 +1,68 @@ #!/bin/bash -#import list from csv -echo "Please clear all feilds except for the file name feild from the csv." -while IFS='\t' read (awk -F, 'NR > 1' { print $1}) -#cd to and then remove 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 + #read PDFDIR + PDFDIR="/home/btmccrea/Downloads/pdfs" + if [ -d $PDFDIR ] + then break else echo -e "Directory not found." fi -done \ No newline at end of file +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/Final" + if [ -d $OUTPUTFOLDER ] + then + break + else + echo -e "Directory not found." + fi +done +#Get the folder with the csv +while : +do + echo -e "What path and file with?" + #read CSVFILE + if [ -f $CSVFILE ] + then + break + else + echo -e "File not found." + fi +done + +#import list from csv +echo "Processing csv." +while IFS=$'\t' read -r FILE +do + echo "FILE $FILE" +# echo "user $USER" +# echo "match $MATCH" +# echo "${array[0]}" +# if [[ "$MATCH" == "Match-Mailable" ]] +# then +# +# echo -e "Processing file $FILE"lY + cp $PDFDIR/"$FILE" $OUTPUTFOLDER +# else +# echo "no match" +# fi +done < /home/btmccrea/Downloads/Smarty_Streets.csv +#FILE=$(cat /home/btmccrea/Downloads/Smarty_Streets.csv) +#echo $FILE +#IFS=$'\t' +#for f in Smarty_Streets.csv +#do +# echo "doing file $f" +# cp $PDFDIR/"$f" $OUTPUTFOLDER +#done + +#cd to and then remove files diff --git a/Sort_and_Merge_Files.sh b/Sort_and_Merge_Files.sh index 30dedb1..703ec5a 100644 --- a/Sort_and_Merge_Files.sh +++ b/Sort_and_Merge_Files.sh @@ -5,23 +5,26 @@ #Get the location of the PDF files echo "What is the location of the PDF files" -read FILE - +#read FILE +FILE=/home/btmccrea/Downloads/output/Only_Good/* +#cd $FILE for FILENAME in $FILE 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 /mnt/tmpfs/Statement-Pages-$LOCATION.pdf; then - mv /mnt/tmpfs/Statement-Pages-$LOCATION.pdf /mnt/tmpfs/temp.pdf + if test -f /home/btmccrea/Downloads/output/Final/Statement-Pages-$LOCATION.pdf + then + mv /home/btmccrea/Downloads/output/Final/Statement-Pages-$LOCATION.pdf /home/btmccrea/Downloads/output/Final/temp.pdf + pdfunite "$FILENAME" /home/btmccrea/Downloads/output/Final/temp.pdf /home/btmccrea/Downloads/output/Final/Statement-Pages-$LOCATION.pdf else - pdfunite "$FILENAME" /mnt/tmpfs/temp.pdf /mnt/tmpfs/Statement-Pages-$LOCATION.pdf -#IF the file doesn't exist create the file with the merge. - pdfunite "$FILENAME" /mnt/tmpfs/Statement-Pages-$LOCATION.pdf - fi; + #IF the file doesn't exist create the file with the merge. + pdfunite "$FILENAME" /home/btmccrea/Downloads/output/Final/Statement-Pages-$LOCATION.pdf + fi #once everything else is doen Make the directory to place the files into #and copy the finished files into it. -mkdir $FILE/Finished/ -cp -r /mnt/tmpfs/Statement-* $FILE/Finished/ +#mkdir $FILE/Finished/ +#cp -r /home/btmccrea/Downloads/output/Final/Statement-* $FILE/Finished/ done exit \ No newline at end of file