From owner-freebsd-questions@FreeBSD.ORG  Sat Feb  4 05:57:26 2006
Return-Path: <owner-freebsd-questions@FreeBSD.ORG>
X-Original-To: freebsd-questions@freebsd.org
Delivered-To: freebsd-questions@freebsd.org
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id AF98E16A420
	for <freebsd-questions@freebsd.org>;
	Sat,  4 Feb 2006 05:57:26 +0000 (GMT) (envelope-from parv@pair.com)
Received: from mta9.adelphia.net (mta9.adelphia.net [68.168.78.199])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 5274F43D49
	for <freebsd-questions@freebsd.org>;
	Sat,  4 Feb 2006 05:57:26 +0000 (GMT) (envelope-from parv@pair.com)
Received: from default.chvlva.adelphia.net ([68.67.248.200])
	by mta9.adelphia.net
	(InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id
	<20060204055725.EAVH14388.mta9.adelphia.net@default.chvlva.adelphia.net>;
	Sat, 4 Feb 2006 00:57:25 -0500
Received: by default.chvlva.adelphia.net (Postfix, from userid 1000)
	id 21F3CB755; Sat,  4 Feb 2006 00:37:00 -0500 (EST)
Date: Sat, 4 Feb 2006 00:37:00 -0500
From: Parv <parv@pair.com>
To: freebsd-questions@freebsd.org
Message-ID: <20060204053659.GA2174@holestein.holy.cow>
Mail-Followup-To: freebsd-questions@freebsd.org, vaaf@broadpark.no
References: <7.0.1.0.2.20060203110425.01744328@broadpark.no>
	<20060203204323.GV1940@merkur.atekomi.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20060203204323.GV1940@merkur.atekomi.net>
Cc: 
Subject: Re: Script to generate names
X-BeenThere: freebsd-questions@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: User questions <freebsd-questions.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-questions>, 
	<mailto:freebsd-questions-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-questions>
List-Post: <mailto:freebsd-questions@freebsd.org>
List-Help: <mailto:freebsd-questions-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-questions>, 
	<mailto:freebsd-questions-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sat, 04 Feb 2006 05:57:26 -0000

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

--