
# UNISRC_ID: @(#)words.sh	26.1	84/07/03  
# Script to turn files (stdin or named files) into a list of words,
# one word per line.

# Usage:  words [-l] [files...]   where -l means "all lower case".

# Tr converts everything other than apostrophe (047) and alpha characters to
# newlines (012), then squeezes out excess newlines.  The lower-case version
# needs separate tr's to avoid squeezing out alpha characters.  The quote
# marks are carefully placed.

	trans=" tr -cs '\047[A-Z][a-z]' '[\012*]' "

	if [ ${1:-no} = "-l" ]
	then
		shift
		trans=${trans}" | tr '[A-Z]' '[a-z]' "
	fi

# Do stdin or all args:

	if [ $# = 0 ]
	then
		eval $trans
	else
		for file in $*
		do
			{ eval $trans ; }  <$file
		done
	fi
