summaryrefslogtreecommitdiff
path: root/os1w5/lettercount.sh
blob: 9ff343694808cb0781923d8b3bc85f7f59eac1e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh

usage() {
	echo "usage: $0 <file> <letter1> [letter2] [letter3] [...]"
	exit 1
}

[[ ! -f "$1" ]] && echo "file does not exist" && usage
[[ "$#" -lt 2 ]] && echo "not enough arguments" && usage

file="$1"
shift
for letter in "$@"; do
	[[ ! "${#letter}" -eq 1 ]] && echo "argument \"$letter\" too long" && usage
	echo "$letter -> `cat $file | tr -cd $letter | wc -c`"
done