Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- directory=$(pwd)
- searchterms="searchterms.txt"
- extension=".end"
- usage() {
- echo "usage: fmat [[[-f file ] [-d directory ] [-e ext]] | [-h]]"
- echo " file - text file containing a return-delimited list of materials"
- echo " directory - directory to process"
- echo " ext - file extension of files to process"
- echo ""
- }
- while [ "$1" != "" ]; do
- case $1 in
- -d | --directory ) shift
- directory=$1
- ;;
- -f | --file ) shift
- searchterms=$1
- ;;
- -e | --extension ) shift
- extension=$1
- ;;
- -h | --help ) usage
- exit
- ;;
- * ) usage
- exit 1
- esac
- shift
- done
- if [ ! -d "$directory" ]; then
- echo "Sorry, the directory '$directory' does not exist"
- exit 1
- fi
- if [ ! -f "$searchterms" ]; then
- echo "Sorry, the searchterms file '$searchterms' does not exist"
- exit 1
- fi
- echo "Searching '$directory' ..."
- for file in "${directory}/*"; do
- printf "File: %sn" ${file}
- [ -e "$file" ] || continue
- printf "%sn" ${file}
- if [ ${file: -3} == ${extension} ]; then
- printf "%s will be processedn" ${file}
- #
- # lots of processing here
- #
- fi
- done
- grep -f searchterms.txt *.end > allchanges.end.res
Add Comment
Please, Sign In to add comment