Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 04 Feb 2006 16:42:43 +0100
From:      Kristian Vaaf <vaaf@broadpark.no>
To:        Parv <parv@pair.com>, Will Maier <willmaier@ml1.net>, freebsd-questions@freebsd.org
Subject:   Re: Script to generate names
Message-ID:  <7.0.1.0.2.20060204163558.01ffedf0@broadpark.no>
In-Reply-To: <20060204053659.GA2174@holestein.holy.cow>
References:  <7.0.1.0.2.20060203110425.01744328@broadpark.no> <20060203204323.GV1940@merkur.atekomi.net> <20060204053659.GA2174@holestein.holy.cow>

next in thread | previous in thread | raw e-mail | index | archive | help

I am flattered over all this assistance.

Thank you indeed Parv, and also Will Maier, you guys have surely 
taught me a lot.

I got my hands full of work currently, but I'll test this script 
ASAP, and get back to you all.

This is going to be great! Here is my copy and paste of it.

--

#!/usr/local/bin/bash
#
#   Generate new names based on lists.
#   $NINJA: invent.sh,v 1.0 2007/11/11 15:09:05 johann Exp $
#
#   Usage: invent 1.txt 2.txt out.txt
#

echo "Combining $1 with $2 to $3."

[ -f "$save" ] && mv -f "$save" "$save--OLD"

{       while read word_1; do
         while read word_2; do

                 printf "%s%s\n%s%s\n" "$word_1" "$word_2" "$word_2" "$word_1"

                 done < "$2"

         done < "$1" } | sort -u >> "$3"

--

Does it look alright so far?

Thanks again,
Vaaf

At 06:37 04.02.2006, Parv wrote:
>in message <20060203204323.GV1940@merkur.atekomi.net>,
>wrote Will Maier thusly...
> >
> > 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...
>...
> > for WORD1 in $(< ${LIST1}); do
>...
> > done
>
>It looks like OpenBSD (3.6) sh is pdksh (see "Shell startup" section;
>process substitution is in "Substitution" section, paragraph 6) ...
>
> 
>http://www.freebsd.org/cgi/man.cgi?query=sh&apropos=0&sektion=0&manpath=OpenBSD+3.6&format=html
>
>
>Process substitution does not work in FreeBSD 6 /bin/sh ...
>
>   # cat p
>   set -x
>   for i in $(< q); do echo "$i"; done
>
>   # cat q
>   polka
>   bikini
>   state
>
>   # sh p
>   +
>
>
>... but in zsh ...
>
>   # zsh p
>   +/home/parv/p:2> i=polka
>   +/home/parv/p:2> echo polka
>   polka
>   +/home/parv/p:2> i=bikini
>   +/home/parv/p:2> echo bikini
>   bikini
>   +/home/parv/p:2> i=state
>   +/home/parv/p:2> echo state
>   state
>
>
>Anyway, here is one solution for FreeBSD /bin/sh ...
>
>   in_1="list1"
>   in_2="list2"
>   save="list3"
>
>   [ -f "$save" ] && mv -f "$save" "$save--OLD"
>   {
>     while read word_1
>     do
>       while read word_2
>       do
>         printf "%s%s\n%s%s\n" \
>           "$word_1" "$word_2" \
>           "$word_2" "$word_1"
>
>         #  If all the possible combinations of all the words are
>         #  needed, remove or comment out the following "break".
>         break
>
>       done <"$in_2"
>     done <"$in_1"
>   } | sort -u >> "$save"
>
>
>Kristian, try the above code with or without the "break",  and
>exchanging "$in_1" & "$in_2".  If "$in_1" file is smaller than
>"$in_2", then the script will end earlier (in comparison to reverse
>situation).
>
>
>   - Parv
>
>--




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