Date: Sat, 4 Feb 2006 16:36:46 -0500 From: Parv <parv@pair.com> To: freebsd-questions@freebsd.org, vaaf@broadpark.no Subject: Re: Script to generate names Message-ID: <20060204213646.GA879@holestein.holy.cow> 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
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 --
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060204213646.GA879>