From 2fb552ed8a90a9adb6ab1a9397567eb77dfbd26b Mon Sep 17 00:00:00 2001 From: btmccrea Date: Wed, 23 Dec 2020 16:26:31 -0500 Subject: [PATCH] Finished Find Addresses. Starte Remove and Sort scripts --- Find_Missing_Addresses.sh | 21 +++++++++++++-------- Removing_Files.sh | 19 +++++++++++++++++++ Sort_and_Merge_Files.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 Removing_Files.sh create mode 100644 Sort_and_Merge_Files.sh diff --git a/Find_Missing_Addresses.sh b/Find_Missing_Addresses.sh index 553c0d6..cf307a1 100755 --- a/Find_Missing_Addresses.sh +++ b/Find_Missing_Addresses.sh @@ -1,22 +1,23 @@ #!/bin/bash - +#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/ + 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/Documents/output/ + read OUTPUTFOLDER + #OUTPUTFOLDER=/home/btmccrea/Documents/output/ if [ -d $PDFDIR ]; then break else @@ -24,19 +25,23 @@ do fi done +#Create the csv and headers for the Addresses. It is tab separated. touch "$OUTPUTFOLDER"Addresses.csv -echo "File, User, Address" > "$OUTPUTFOLDER"Addresses.csv +echo -e "File\tUser\tAddress" > "$OUTPUTFOLDER"Addresses.csv #FILES=$(ls $PDFDIR) cd $PDFDIR #echo $FILES -#* represensts All files in the current directory +#*.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) - echo "$f, $USER, '$ADDRESS1 $ADDRESS2'" >> "$OUTPUTFOLDER"Addresses.csv + #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 exit diff --git a/Removing_Files.sh b/Removing_Files.sh new file mode 100644 index 0000000..9619424 --- /dev/null +++ b/Removing_Files.sh @@ -0,0 +1,19 @@ +#!/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 + break + else + echo -e "Directory not found." + fi +done \ No newline at end of file diff --git a/Sort_and_Merge_Files.sh b/Sort_and_Merge_Files.sh new file mode 100644 index 0000000..30dedb1 --- /dev/null +++ b/Sort_and_Merge_Files.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +#get directory for pdf files +#get output directory for files + +#Get the location of the PDF files +echo "What is the location of the PDF files" +read FILE + +for FILENAME in $FILE +do +#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 + 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; +#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/ +done +exit \ No newline at end of file