Advertisement
metalx1000

Document Search Script

Feb 9th, 2018
1,181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.80 KB | None | 0 0
  1. #!/bin/bash
  2. #created by Kris Occhipinti - https://filmsbykris.com
  3. #Fri Feb 9 2018
  4. #Licensed under GPLv3 - https://www.gnu.org/licenses/gpl-3.0.txt
  5. ### This script converts all pdf files in a given dir to a one line text file  for quick searching   ###
  6.  
  7. dir="/home/user/Documents"
  8. output="/home/user/.docsearch"
  9. func="$1"
  10. q="$*"
  11.  
  12. if [ "$#" -lt "1" ]
  13. then
  14.   echo "Input needed."
  15.   echo "To update: $0 update"
  16.   echo "To search: $0 mazda"
  17.   exit 1
  18. fi
  19.  
  20. function update(){
  21.   find "$dir" -iname "*.pdf"|while read pdf;
  22.   do
  23.     echo -n "${pdf}|";
  24.     pdftotext "$pdf" - |sed ':a;N;$!ba;s/\n/ /g';
  25.     echo "";
  26.   done > "$output"
  27. }
  28.  
  29. function main(){
  30.   if [ "$func" = "update" ]
  31.   then
  32.     update;
  33.   else
  34.     echo "Searching for $q"
  35.     grep -i "$q" "$output"|cut -d\| -f1
  36.   fi
  37. }
  38.  
  39. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement