Se o seu shell é bash versão 4:
declare -i total=0
declare -A type
if [ -s "$1" ]; then
while IFS=, read name id job; do
[[ $job =~ ^[[:space:]]*(.+)[[:space:]]*$ ]] &&
(( type["${BASH_REMATCH[1]}"]++, total++ ))
done < "$1"
for job in "${!type[@]}"; do
printf "There are %d '%s' employees.\n" ${type["$job"]} "$job"
done
echo "There are a total of $total employees in the company"
else
echo "ERROR: file '$1' does not exist or has zero size."
fi
Ou use o awk:
awk -F' *, *' '
{ type[$3]++; total++ }
END {
for (job in type)
printf "There are %d '\''%s'\'' employees.\n", type[job], job
print "There are a total of", total, "employees in the company"
}
' "$1"