Skip to content

Instantly share code, notes, and snippets.

@courtneymyers
Last active January 12, 2017 14:17
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 courtneymyers/53ae9df7dba7eeff5a23c83a7e132f27 to your computer and use it in GitHub Desktop.
Save courtneymyers/53ae9df7dba7eeff5a23c83a7e132f27 to your computer and use it in GitHub Desktop.
Bash script for searching for specific terms found within PDFs in the current directory. Relies on the 'pdftotext' command line utility.
#!/bin/bash
#echo "This script will search PDFs in this directory. Enter search term:"
#read term
#echo "Results found for \"${term}\":"
#find . -name '*.pdf' -exec sh -c "pdftotext '{}' - | grep --label='{}' --color --with-filename --line-number --ignore-case '${term}'" \;
# check for input arguments
if [ $# -eq 0 ] ; then
echo "You must enter a search term."
exit 1
fi
echo "Searching PDFs in this directory for \"$1\"..."
find . -name '*.pdf' -exec sh -c "pdftotext '{}' - | grep --label='{}' --color --with-filename --line-number --ignore-case '$1'" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment