Find Words - match

The match command uses Korn shell pattern-matching characters to find words in a dictionary. It can be used to help with crossword puzzles, or test your patterns.

					#!/bin/ksh
					#
					#     match - Korn shell word-finder
					#
					# Check usage
					if (($# < 1 || $# > 2))
					then
					print "Usage: $0 pattern [file]"
					exit 1
					fi
					# Check/set DICT to word dictionary
					: ${DICT:=${2:-/usr/dict/words}}
					# Open $DICT for input
					exec 0<$DICT
					# Read each word into WORD
					while read WORD
					do
					# This command didn't work on all systems. If
					# it doesn't on yours, use this instead of
					# exec 0<$DICT:
					#     cat $DICT | while read WORD
					#
					# If WORD matches the given pattern,
					# print the match
					[[ $WORD = $1 ]] && print - $WORD
					done
				

Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.