RosettaCodeData/Task/Letter-frequency/Ksh/letter-frequency.ksh

19 lines
337 B
Bash
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
#!/bin/ksh
# Count the occurrences of each character
######
# main #
######
typeset -iA freqCnt
while read; do
2026-04-30 12:34:36 -04:00
for ((i=0; i<${#REPLY}; i++)); do
(( freqCnt[${REPLY:i:1}]++ ))
done
done < $0 ## Count chars of this code file
2023-07-01 11:58:00 -04:00
for ch in "${!freqCnt[@]}"; do
2026-04-30 12:34:36 -04:00
[[ ${ch} == ?(\S) ]] && print -- "${ch} ${freqCnt[${ch}]}"
2023-07-01 11:58:00 -04:00
done