count a specific char in file

chenqi@pek-qchen1-d1:~/mypro/bash/count_specific_char$ ./count.sh c count.sh
10

chenqi@pek-qchen1-d1:~/mypro/bash/count_specific_char$ ./count.sh \" count.sh
4


#!/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
相關文章
相關標籤/搜索