Fixed problems with 2020 file and logic improvments

This commit is contained in:
btmccrea committed 2021-01-24 08:36:11 -05:00
1 parent 2fb552ed8a
commit 628cffcbda
3 files changed
+116 -43

No files matched your search

+45 -24
View File
@@ -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