mk-aspell-dict.sh (Source)

#!/bin/bash
# generates an *aspell* "dictionary"
# from a list of misspelled words found by aspell.
set -o errexit
# Configuration ----------------------------------------------------
HEADER=personal_ws-1.1
LANG=en
# Commands ---------------------------------------------------------
ASPELL=/usr/bin/aspell
CAT=/bin/cat
ECHO=/bin/echo
READLINK=/bin/readlink
RM=/bin/rm
SORT=/usr/bin/sort
UNIQ=/usr/bin/uniq
WC=/usr/bin/wc
# Script -----------------------------------------------------------
if [ -z "$1" ];
then
    $ECHO Error: no source specified.
    exit 1
fi
# normalize paths
# aspell will not resolve shell variables or perform expansion
src=`readlink -fn "$1"`
if [ ! -r "$src" ];
then
    $ECHO Error: "$src"  does not exist or is not readable
    exit 1
fi
if [ -z "$2" ];
then
    dest="$1.pws"
    $ECHO Destination not specified, using \'$dest\'
else
    # use `readlink` to get absolute path.
    dest=`$READLINK -fn "$2"`
fi
templist=/tmp/wordlist
# generate a wordlist from words considered misspelled by aspell
# remove duplicates with `sort | uniq`
$ASPELL --rem-extra-dicts "$dest" list < "$src"\
| $ASPELL clean\
| $SORT\
| $UNIQ > "$templist"
# generate the header for the pws file with the number of words
# wc -l will output:
# [numlines] [filenames]
# (separated by space)
wordcount=`$WC -l "$templist"`
$ECHO "$HEADER $LANG ${wordcount% *}" > "$dest"
$CAT "$templist" >> "$dest"
$RM "$templist"
$ECHO Generated dictionary at \'$dest\'.