#! /bin/bash -eu
# Last edited on 2026-06-28 06:57:27 by stolfi

# Computes the counts of final letters of words.
# Assumes that the input is all lowercase with no punctuation
# and words separated by blanks.

export LC_ALL=en_US.utf8
export LANG=en_US.utf8
export LC_CTYPE=en_US.utf8

echo "# -*- coding: utf-8 -*-"
echo "# -*- coding: utf-8 -*-" > .foo

cat \
  | egrep -v -e '^ *([#]|$)' \
  | sed \
      -e '/^[ ]*[#]/d' \
      -e '/^[ ]*$/d' \
      -e 's:<.*>::g' \
      -e 's:^[ ]*: :g' \
      -e 's:[ ]*$: :g' \
      -e 's:[ ][ ][ ]*: :g' \
      -e 's:\([^ ]\) :@\1.@:g' \
  | gawk '//{ gsub(/[@]/, "\n", $0); print}' \
  | egrep -e '[.]' \
  | sort | uniq -c \
  | sort -b -k1,1nr 
