I'm hoping one of you bash guru's gets this.
I'm grepping through some large files and adding up the occurrences of particular patterns. I've got it where it outputs the number of occurrences from each file, but how to do I get it to add them all together for a total. It's got to be pretty easy I hope. Here is what I have. Any help would be great.
Code:
read -p "What do the file names start with? : " NAME
read -p "What pattern do you want to find? : " PATTERN
LIST=`ls $NAME*.*`
echo ""
echo "############### Here is a list of files ###################"
echo ""
echo $LIST
echo ""
for name in ${LIST} ; do
echo $name has -
cat $name | grep -i "$PATTERN" | wc -l
echo ""
done
exit 0
As an after thought, how do I get the count to show right after "echo $name has -" instead of below it?
Thanks again for the help guys!