Date: Sat, 4 Feb 2006 00:37:00 -0500 From: Parv <parv@pair.com> To: freebsd-questions@freebsd.org Subject: Re: Script to generate names Message-ID: <20060204053659.GA2174@holestein.holy.cow> In-Reply-To: <20060203204323.GV1940@merkur.atekomi.net> References: <7.0.1.0.2.20060203110425.01744328@broadpark.no> <20060203204323.GV1940@merkur.atekomi.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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?20060204053659.GA2174>