Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to combine and/or permute the words from a list up to 3 times. For example:

If I have one list with:


and another list with:


it should produce combinations like:


The logic is the word from any list can be repeated up to 3 times, no more. But in any order and any permutation. How can I achieve this?

share|improve this question
Following your logic 112233112233112233appleorangecafeappleorangecafeappleorangecafe would be your longest combination from your example, right? – nixda Jul 13 '13 at 13:50
right, exactly. – FernandoSBS Jul 13 '13 at 13:53
@nixda where are you? – FernandoSBS Jul 13 '13 at 14:15
Do you need a piece of software or could it be code? – Andy Jul 13 '13 at 16:44
Need a piece of software. You know, I've tried googling for it for like 1 hour straight and can't believe that I couldn't find a program that do this that I want. there is a website which do almost it all (but only combine, no permute) but it limits the word count. So I believe it must be a local software. – FernandoSBS Jul 13 '13 at 18:36
up vote 1 down vote accepted

command line, eq cat test test test|shuf|head -n 18|grep -v ^$|paste -s -d"\0":

powershell $r=New-Object Random;1..3^|%{gc test}^|select -f 18^|%{[array]$A+=$_};1..$A.Count^|%{$A[$r.Next(0,$A.Count-1)]}^|?{$_.Length -ne 0}^|%{$S+=$_};$S

cat test test test approximate correspondence `1..3^|%{gc test}

shuf approximate correspondence (powershell shuffle strings in pipe):

$r=New-Object Random; ... %{[array]$A+=$_};1..$A.Count^|%{$A[$r.Next(0,$A.Count-1)]}

head -n 18 approximate correspondence select -f 18

grep -v ^$ approximate correspondence ?{$_.Length -ne 0}

paste -s -d"\0" approximate correspondence %{$S+=$_};$S

when see command line:

cat test test test|shuf|head -n 18|grep -v ^$|paste -s -d"\0"

imagined the file type - test:



use file test:



$r=New-Object Random;1..3|%{gc test}|select -f 18|%{[array]$A+=$_};1..$A.Count|%{$A[$r.Next(0,$A.Count-1)]}|?{$_.Length -ne 0}|%{$S+=$_};$S

For the purpose of generating text from templates are more suitable in another language.

It needs a specialist in Common Lisp and C. May be an expert Haskell.

If necessary mathematical symbolic computation then it is likely Maxima.

But you can always do whatever tools that are not designed for specific tasks ))).

It will be very nice if you describe your problem completely. Architecturally.

share|improve this answer
this all should be put in a powershell script? Does it output all the combinations? – FernandoSBS Jul 14 '13 at 20:24
sorry but I don't understand your post, could you please explain each step better? – FernandoSBS Jul 14 '13 at 21:53
i've forgot a password for a rar file and i'm trying to figure it out with the common words I use. – FernandoSBS Jul 15 '13 at 2:25
@FernandoSBS use Passware Kit Professional ... – STTR Jul 15 '13 at 2:47
great program. Only drawback is that I can't make it use ONLY the words in a wordlist, since I must set the number of characters. – FernandoSBS Jul 29 '13 at 11:44

If you have a Linux computer handy (or Mac OS X might do), create a file called test with this content:


followed by six empty lines. Then run this:

cat test test test|shuf|head -n 18|grep -v ^$|paste -s -d"\0"

cat concatenates the files, shuf shuffles the lines, head retrieves the first 18 lines (so you can have your maximum string), grep excludes empty lines and paste glues the line together.

EDIT: Sorry, only noticed the windows tag after posting. You can install Cygwin for this, but you might as well just take the principle and implement in something else.

share|improve this answer
any way to do it with powershell? also, what about the empty lines, if I have a 30 word list then I must put 30 empty lines in the end? – FernandoSBS Jul 13 '13 at 23:33
Probably, but I wouldn't know how. You may be able to do it with Excel too (shuffle rows, transpose, merge). – Paulo Almeida Jul 13 '13 at 23:39
Yes, with this method you would have to put as many empty lines at the end as you have words, but if you implement it in a different way you can have just the words and retrieve a random number of them. I just didn't know of any immediate way to do it on the command line. – Paulo Almeida Jul 13 '13 at 23:43
ok so how to output it to a text file? – FernandoSBS Jul 14 '13 at 0:09
On linux, redirect the output by appending "> filename" to the command. – Paulo Almeida Jul 14 '13 at 0:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .