updating
This commit is contained in:
1 parent
3cf3404f73
commit
fc89b0662d
1 file changed
+84
-31
@@ -1,41 +1,94 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Welcome! It must be the start of a new year! In order to get started with sorting and merging the PDF documents I need to know a little more information."
|
||||
echo
|
||||
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
|
||||
|
||||
read -p 'Where is the directory that has the PDF statments with address? ' PDFDIR
|
||||
#read PDFDIR
|
||||
#Get the folder for the output file.
|
||||
while :
|
||||
echo
|
||||
read -p 'What output directory do you want for the sorted PDFs? ' OUTPUTFOLDER
|
||||
#read OUTPUTFOLDER
|
||||
echo
|
||||
echo "The PDFs statments are in $PDFDIR?"
|
||||
echo "The output folder will be $OUTPUTFOLDER."
|
||||
echo
|
||||
read -p "Press Enter to continue" </dev/tty
|
||||
echo
|
||||
|
||||
|
||||
#./Find_Missing_Addresses.sh $PDFDIR $OUTPUTFOLDER
|
||||
|
||||
#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
|
||||
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."
|
||||
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
|
||||
|
||||
|
||||
./Find_Missing_Addresses.sh $PDFDIR $OUTPUTFOLDER
|
||||
|
||||
read -r -p "Do you want to continue? [Y/n]" response
|
||||
echo "All done sorting!" You can find all the Files in $OUTPUTFOLDER!"
|
||||
echo
|
||||
echo
|
||||
read -r -p "Do you want to continue? [Y/n]" response
|
||||
response=${response,,} # tolower
|
||||
if [[ $response =~ ^(y| ) ]] || [[ -z $response ]]; then
|
||||
./Sort_and_Merge_Files.sh $PDFDIR $OUTPUTFOLDER
|
||||
fi
|
||||
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
|
||||
Reference in new issue
Block a user