1754102 Members
3306 Online
108811 Solutions
New Discussion юеВ

using awk

 
albanese
Occasional Advisor

using awk

How could i create all possible combinations of a given string containing 3 to 5 elements using awk.
eg :
number1|number2,number3
number4|number5,number6,number7,
number8|number9,number10,number11,number12

i would like to produce a file with all the possible combinations
eg:
number1|number2|number3
number2|number1|number3
number3|number2|number1

number4|number5|number6|number7
number5|number4|number6|number7
number6|number5|number4|number7
number7|number5|number6|number4

and so on for the other with 5 elements.

Thanks in advance ..
6 REPLIES 6
Peter Godron
Honored Contributor

Re: using awk

Peter Godron
Honored Contributor

Re: using awk

Hi (again),
can you please comment and let us know why this solution "didn't really help your problem" ? Seems to me a near perfect (formatting only ) match.
albanese
Occasional Advisor

Re: using awk

Hello

First of all thanks for the reply..
What i am looking for is not the permutations of my numbers.
I triend to explain in the examples that i wrote above. i am looking to the script but i havent reached a solutions yet.

Thanks
albanese
Occasional Advisor

Re: using awk

cheers
Peter Godron
Honored Contributor

Re: using awk

Hi,
what was the solution ?

I like to regard the forums as a knowledge treasure, which relies on previous contributions. If in the future, somebody else needs a solution to a similar problem to yours, your comments can make all the difference!

Could you please detail your solution, so other people may benefit in future.
Patrick Wallek
Honored Contributor

Re: using awk

The script referenced above should give you what you want.

The output from that script is:

$ sh ./permut1.awk 1 2 3
1 2 3
1 3 2
2 1 3
2 3 1
3 2 1
3 1 2

The output can be redirected to a file quite easily.

If this is not what you want, more explanation is in order.