wf.sh
#!/bin/bash
ARGS=1
E_BADARGS=65
E_NOFILE=66
if [ $# -ne "$ARGS" ];then
echo "Usage:`basename $0` filename"
exit $E_BADARGS
fi
if [ ! -f "$1" ];then
echo "File \"$1\" does not exist."
exit $E_NOFILE
fi
sed -e 's/\,/ /g' -e 's/ /\n/g' $1 | tr A-Z a-z | sort | uniq -c | sort -nr
exit 0
验证:
[root@patrolagent ~]# cat 1.txt
aaa bbb
ddd ccc
[root@patrolagent ~]# sh wf.sh
Usage:wf.sh filename
[root@patrolagent ~]# sh wf.sh aa
File "aa" does not exist.
[root@patrolagent ~]# sh wf.sh 1.txt
2
1 ddd
1 ccc
1 bbb
1 aaa
[root@patrolagent ~]#