#!/bin/sh USAGE="usage: search-count.sh " # # script to search and count words in a directory # uses "read" to provide interaction with user # (alternate use would be to require user to provide # data when launching script) # # while true # do echo "SEARCH string to count: " read STR echo "Search Directory: " read DIR echo " --------- " echo " --------- " echo "Searching for $STR in $DIR ..." echo " --------- " echo " " echo " " echo " " echo " --------- " > output-search-count.txt echo "Searching $DIR ..." | tee -a output-search-count.txt echo " " echo " " echo " --------- " >> output-search-count.txt | tee -a output-search-count.txt echo "Name of file and the number of times $STR is found in $DIR" | tee -a output-search-count.txt echo " " echo " --------- " >> output-search-count.txt | tee -a output-search-count.txt find $DIR -type f -exec grep -i -l $STR {} \; \ -exec grep -i -c $STR {} \; | tee -a output-search-count.txt # done echo " --------- " >> output-search-count.txt #echo "Search completed"