Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@moose-byte
Created December 31, 2016 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moose-byte/bfe1913b3d49e183d68b1b684e9c88e5 to your computer and use it in GitHub Desktop.
Save moose-byte/bfe1913b3d49e183d68b1b684e9c88e5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# pdftotextOnDir
# Runs pdftotext on all files in a directory
# Author - Brendan Heussler (bheussler@gmail.com)
# argument 1 - Input Directory
# argument 2 - Output Directory
input_directory=$1 # Input Directory
output_directory=$2 # Output Directory
# Check to see if the input directory exists
if [ -d "$input_directory" ]; then
echo "Input Directory Exists"
else
echo "Input Directory Does Not Exist"
echo "Terminating $0"
exit 1
fi
# Check to see if the output directory exists
if [ -d "$output_directory" ]; then
echo "Output Directory Exists"
else
echo "Output Directory Does Not Exist"
echo "Creating Output Directory"
mkdir $output_directory
fi
# Run pdftotext on all files in the input directory
for file in $input_directory*
do
echo "Running pdftotext on $file"
file_basename=$(basename $file .pdf)
output_filename=${file_basename}.txt
pdftotext "$file" "$output_directory$output_filename"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment