I have a file: test.txt with a sentence on each line.
Hello World
99 Bottles of Beer
Humpty Dumpty Sat on the wall
I wish to produce an output displaying all combinations of the input from this file (i.e. 2n-1 combinations). In the above instance, the algorithm will spill out the following – Each combination to be separated with a pipe (|)
Hello World
99 Bottles of Beer
Humpty Dumpty Sat on the wall
Hello World | 99 Bottles of Beer
Hello World | Humpty Dumpty Sat on the wall
99 Bottles of Beer | Humpty Dumpty Sat on the wall
Hello World | 99 Bottles of Beer | Humpty Dumpty Sat on the wall
Ideally, I would like this to be done in bash or python or perl scripting but I am open to suggestions.
produces
If you don’t like the style of
'\n'.join()(I am not sure I do), you could replace it with an explicit loop:This is slightly more verbose, but is more economical.