Sponsored Content
Top Forums Shell Programming and Scripting Arbitrary permutation and combination script Post 302657559 by complex.invoke on Monday 18th of June 2012 03:05:20 AM
Old 06-18-2012
MySQL Arbitrary permutation and combination script

Code:
#!/bin/bash
# permutation_combination.sh

# Version: 2.0
# Author : YongYe <complex.invoke@gmail.com>

arg0=-1
argv=${3}
number=${2}
eval ary=({1..${1}})
length=${#ary[@]}
percom(){ nsloop i ${1} number${2} ${3} ${4} ${5}; }
invoke(){ echo $(percom ${argu} nsloop -1) prtcom $(percom ${argu}); }
permut(){ echo -n "${1} arg${i} ${2} "; (( ${#} != 0 )) && echo -n " length "; }
combin(){ (( ${#} != 0 )) && echo -n "${1} arg$((i+1)) arg${i} length " || echo -n "arg$((i+1)) "; }
prtcom(){ num=0; for i in ${@}; do echo -n ${ary[${!i}]}; (( ++num != number )) && echo -n .; done; echo; }

nsloop()
{ 
    local arc arg
    arg=${1//arg}
    for((${1}=${2}+1; ${1}<${3}; ++${1})); do 
         if [[ ${1//[0-9]} == arg ]]; then
               for((arc=1; arc!=arg; ++arc)); do
                    (( ${1} == arg${arc} )) && continue 2
               done
         fi
         eval eval \\\$\{{4..${#}}\}
    done
}

case ${3} in
     p) argu="-0 +1 permut" ;;
     c) argu="-1 +0 combin" ;; 
esac

$(invoke)

Invoke the script:
C 4 3
Code:
[root@node2 ~]# bash permutation_combination.sh 4 3 c
1.2.3
1.2.4
1.3.4
2.3.4

P 4 3
Code:
[root@node2 ~]# bash permutation_combination.sh 4 3 p | xargs -n 6
1.2.3 1.2.4 1.3.2 1.3.4 1.4.2 1.4.3
2.1.3 2.1.4 2.3.1 2.3.4 2.4.1 2.4.3
3.1.2 3.1.4 3.2.1 3.2.4 3.4.1 3.4.2
4.1.2 4.1.3 4.2.1 4.2.3 4.3.1 4.3.2

C 8 5
Code:
[root@node2 ~]# bash permutation_combination.sh 8 5 c | xargs -n 8
1.2.3.4.5 1.2.3.4.6 1.2.3.4.7 1.2.3.4.8 1.2.3.5.6 1.2.3.5.7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.1
3.1.2.4.5 3.1.2.5.4 3.1.4.2.5 3.1.4.5.2 3.1.5.2.4 3.1.5.4.2 3.2.1.4.5 3.2.1.5.4
3.2.4.1.5 3.2.4.5.1 3.2.5.1.4 3.2.5.4.1 3.4.1.2.5 3.4.1.5.2 3.4.2.1.5 3.4.2.5.1
3.4.5.1.2 3.4.5.2.1 3.5.1.2.4 3.5.1.4.2 3.5.2.1.4 3.5.2.4.1 3.5.4.1.2 3.5.4.2.1
4.1.2.3.5 4.1.2.5.3 4.1.3.2.5 4.1.3.5.2 4.1.5.2.3 4.1.5.3.2 4.2.1.3.5 4.2.1.5.3
4.2.3.1.5 4.2.3.5.1 4.2.5.1.3 4.2.5.3.1 4.3.1.2.5 4.3.1.5.2 4.3.2.1.5 4.3.2.5.1
4.3.5.1.2 4.3.5.2.1 4.5.1.2.3 4.5.1.3.2 4.5.2.1.3 4.5.2.3.1 4.5.3.1.2 4.5.3.2.1
5.1.2.3.4 5.1.2.4.3 5.1.3.2.4 5.1.3.4.2 5.1.4.2.3 5.1.4.3.2 5.2.1.3.4 5.2.1.4.3
5.2.3.1.4 5.2.3.4.1 5.2.4.1.3 5.2.4.3.1 5.3.1.2.4 5.3.1.4.2 5.3.2.1.4 5.3.2.4.1
5.3.4.1.2 5.3.4.2.1 5.4.1.2.3 5.4.1.3.2 5.4.2.1.3 5.4.2.3.1 5.4.3.1.2 5.4.3.2.1


Last edited by complex.invoke; 08-26-2012 at 04:52 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Combination Of commands

Hello All, I just wanted to know what are the different ways of using commands in combination. The most common one which i know is using pipes. Also grouping is also done like ( ls; date) where output of both the commands is displayed. Are there any other ways of combining various... (2 Replies)
Discussion started by: rahulrathod
2 Replies

2. Shell Programming and Scripting

Combination backup/VI script

I was needing a script that basically covers my butt, lol. I have the nasty habit of making many changes without backing up files, and then after a ton of changes, if I have to go back to the original version, it makes it harder to go back. Now, I have a script that takes a file, renames it to... (3 Replies)
Discussion started by: cbo0485
3 Replies

3. What is on Your Mind?

How To Analyze This (Cryptography Random?) Permutation...?

Hi to all of you guys, I'm new here... May this thread fits on this section. A friend of mine gave me this enigma to do, written in excel. I attach the file below, name New.xls. Enigma: There are 10^20 possibilities of tables (Table1, Table 2, Table 3, Table 4, Table 5,...), with ten rows (row... (3 Replies)
Discussion started by: lucky7
3 Replies

4. Shell Programming and Scripting

Combination of case and If else in shell script

Would it be right forme to combine case statement and if else in one shell script? Would it work? (2 Replies)
Discussion started by: Pauline mugisha
2 Replies

5. Shell Programming and Scripting

Select combination unique using shell script

Hi All, bash-3.00$ gzgrep -i '\ ExecuteThread:' /******/******/******/******/stdout.log.txt.gz <Jan 7, 2012 5:54:55 PM UTC> <Error> <WebLogicServer> <BEA-000337> < ExecuteThread: '414' for queue: 'weblogic.kernel.Default (self-tuning)' has been busy for "696" seconds working on the request... (4 Replies)
Discussion started by: osmanux
4 Replies

6. Shell Programming and Scripting

[Solved] Permutation

Hi, I am trying to permutate each column (Except for IDS). file.txt FID IID TOAST1 TOAST2 TOAST3 ID3 ID3 1 -9 2 ID4 ID4 2 1 1 ID1 ID1 -9 -9 1 ID8 ID8 1 1 -9 ID12 ID12 1 2 2 for toast1 column, there are two 1's, two 2's and one -9. Having the same number of denominations,... (2 Replies)
Discussion started by: johnkim0806
2 Replies

7. Shell Programming and Scripting

Help with bash script to open arbitrary # of independent xterms

I run multiple processes that require I pop open multiple xterms, how can I do this in a script and have each xterm colored differently and labled for the servername they represent, for example if I do ssh username@serverip I would need the xterm to be opened with that servername at the top and... (3 Replies)
Discussion started by: smth333
3 Replies

8. Shell Programming and Scripting

Permutation Words in awk

i have 13 different words. I need to get permutations like all combinations of this words: word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12 word13 But the combinations only should be 12 words long. Is there a fast efficient way to do this? Maybe with linux tool... (1 Reply)
Discussion started by: watcherpro
1 Replies

9. Shell Programming and Scripting

Basic Combination Shell Script

I need to have a script read a file that has a list of words in a single column like below:Black Blue Brown Orange Red Yellow Green White Purple Silver Grey Tan Then print to another file just all of the two-word possible combinations. Example: Black,Blue Anyone want to take a... (4 Replies)
Discussion started by: vespasian
4 Replies

10. Shell Programming and Scripting

PHP parametric + bash script combination

Hello, I have a simple bash script and I manually run this script to put a file into related directory in apache normally. I need to run it in php with parameter. My target is to get a download link by running below script but I do not know anything about php. Here is my bash script: run.sh... (6 Replies)
Discussion started by: baris35
6 Replies
All times are GMT -4. The time now is 06:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy