#!/bin/bash count=0 spec=$1 file=$2 for word in `cat $file`; do for c in `echo $word | sed -e 's/\(.\)/\1 /g'`; do [ "$c" == "$1" ] && count=$((count+1)) done done echo $count