Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Feb 2006 14:43:23 -0600
From:      Will Maier <willmaier@ml1.net>
To:        freebsd-questions@freebsd.org
Subject:   Re: Script to generate names
Message-ID:  <20060203204323.GV1940@merkur.atekomi.net>
In-Reply-To: <7.0.1.0.2.20060203110425.01744328@broadpark.no>
References:  <7.0.1.0.2.20060203110425.01744328@broadpark.no>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Feb 03, 2006 at 11:08:04AM +0100, Kristian Vaaf wrote:
> I'm looking for pointers on how to make a simple shell script that will
> generate new names based on words (one word per line) from two different
> files, and output these to a third file.

How bout this? Works on OpenBSD's sh; I assume it works on Free's sh
as well. Might take a while to run, though...

#!/bin/sh

notify () {
    if [ ${VERBOSE} ]; then
	echo "===> $*"
    fi
}

VERBOSE=1
LIST1=/path/to/list1
LIST2=/path/to/list2
LIST3=/path/to/list3
NEWWORDCT=0

if [ ! -f "${LIST3}" ]; then
    touch ${LIST3}
fi

for WORD1 in $(< ${LIST1}); do
    for WORD2 in $(< ${LIST2}); do
	echo "${WORD1}${WORD2}" >> ${LIST3}
	echo "${WORD2}${WORD1}" >> ${LIST3}
	NEWWORDCT=$((NEWWORDCT + 2))
    done
done

sort ${LIST3} | uniq > ${LIST3}-sorted

notify "Created ${NEWWORDCT} new words in file ${LIST3}; a sorted version"
notify "can be found at ${LIST3}-sorted."
-- 

o--------------------------{ Will Maier }--------------------------o
| jabber:..wcmaier@jabber.ccc.de | email:..........wcmaier@ml1.net |
| \.........wcmaier@cae.wisc.edu | \..........wcmaier@cae.wisc.edu |
*------------------[ BSD Unix: Live Free or Die ]------------------*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060203204323.GV1940>