From owner-freebsd-questions@FreeBSD.ORG Sat Feb 4 21:36:48 2006 Return-Path: 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 D5A4F16A422 for ; Sat, 4 Feb 2006 21:36:48 +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 3E46A43D48 for ; Sat, 4 Feb 2006 21:36:48 +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 <20060204213647.YLQL14388.mta9.adelphia.net@default.chvlva.adelphia.net>; Sat, 4 Feb 2006 16:36:47 -0500 Received: by default.chvlva.adelphia.net (Postfix, from userid 1000) id 93FF0B6A2; Sat, 4 Feb 2006 16:36:46 -0500 (EST) Date: Sat, 4 Feb 2006 16:36:46 -0500 From: Parv To: freebsd-questions@freebsd.org, vaaf@broadpark.no Message-ID: <20060204213646.GA879@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> <20060204053659.GA2174@holestein.holy.cow> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060204053659.GA2174@holestein.holy.cow> 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Feb 2006 21:36:49 -0000 in message <20060204053659.GA2174@holestein.holy.cow>, wrote Parv thusly... > ... > 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" > This is just broken at "break" as you would get combination of all the words from "$in_1" only w/ the first word in "$in_2". Remove "break", and code works to generate all the possible combinations. With "break" there, i was going for line wise pairs: word from line 1 from file 1 is paired w/ word from line 1 from file 2; word from line 2 from file 1 paired w/ word from line 2 from file 2. Of course, i forgot that that will cause the file 2 to be read from the start. What is needed is (involving use of fseek(3) & ftell(3)) ... - open file 2 to read; save the current position, say in variable pos - inside the loop reading file 1, ... + read a word from line 2 starting at $pos + print word pairs + overwrite $pos w/ the current position in file 2 In any case, below is the version to generate all the pairs (does not emits line wise pairs as stated above) ... #!/bin/sh in_1="list1" in_2="list2" save="list3" [ -f "$save" ] && mv -f "$save" "$save--OLD" { while read word_1 do [ -z "$word_1" ] && continue while read word_2 do [ -z "$word_2" ] && continue printf "%s%s\n%s%s\n" \ "$word_1" "$word_2" \ "$word_2" "$word_1" done <"$in_2" done <"$in_1" } | sort -u >> "$save" exit - Parv --