Files
eoy-pdf-sortandmerge/Find_Missing_Addresses.sh
T

50 lines
1.4 KiB
Bash
Executable File

#!/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/
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/
if [ -d $PDFDIR ]; then
break
else
echo -e "Directory not found."
fi
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)
cd $PDFDIR
#echo $FILES
#*.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
exit