Guest User

Untitled

a guest
Mar 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #!/bin/bash
  2. directory=$(pwd)
  3. searchterms="searchterms.txt"
  4. extension=".end"
  5.  
  6. usage() {
  7. echo "usage: fmat [[[-f file ] [-d directory ] [-e ext]] | [-h]]"
  8. echo " file - text file containing a return-delimited list of materials"
  9. echo " directory - directory to process"
  10. echo " ext - file extension of files to process"
  11. echo ""
  12. }
  13.  
  14. while [ "$1" != "" ]; do
  15. case $1 in
  16. -d | --directory ) shift
  17. directory=$1
  18. ;;
  19. -f | --file ) shift
  20. searchterms=$1
  21. ;;
  22. -e | --extension ) shift
  23. extension=$1
  24. ;;
  25. -h | --help ) usage
  26. exit
  27. ;;
  28. * ) usage
  29. exit 1
  30. esac
  31. shift
  32. done
  33.  
  34. if [ ! -d "$directory" ]; then
  35. echo "Sorry, the directory '$directory' does not exist"
  36. exit 1
  37. fi
  38.  
  39. if [ ! -f "$searchterms" ]; then
  40. echo "Sorry, the searchterms file '$searchterms' does not exist"
  41. exit 1
  42. fi
  43.  
  44. echo "Searching '$directory' ..."
  45. for file in "${directory}/*"; do
  46. printf "File: %sn" ${file}
  47. [ -e "$file" ] || continue
  48. printf "%sn" ${file}
  49. if [ ${file: -3} == ${extension} ]; then
  50. printf "%s will be processedn" ${file}
  51. #
  52. # lots of processing here
  53. #
  54. fi
  55. done
  56.  
  57. grep -f searchterms.txt *.end > allchanges.end.res
Add Comment
Please, Sign In to add comment