language: Bash (bash 4.0.35)
date: 205 days 3 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
 
# process standard input
while read -a line; do
    for word in ${line[@]}; do
        len=${#word}
        lengths[len]=$((${lengths[len]}+1))
 
        for((j=0; j<${#word};++j)); do
            letters+=${word:j:1}
        done
    done
done
 
echo "character statistics:"
echo $letters | fold -w 1 | sort | uniq -c | sort -rn
 
echo "word length statistics:"
for i in ${!lengths[*]}; do
    echo "Found ${lengths[i]} words of length $i"
done