f= parameter specifys the set of fields, n= parameter defines the combination, and a=parameter specifies the output field name. Permutation output is possible by specifying -p option.
mcombi a= f= n= [s=] [k=] [-p] [-dup] [i=] [o=] [-nfn] [-nfno] [-x] [-q] [--help] [--version]
a= Name of the field to be added. f= Compute the combinations for the set of field name(s) (multiple fields can be specified) specified . Enumerate all combinations of the array of values in the fields specified. n= Number of combinations. When you increase the number of combinations, note that the number of output records will increase exponentially. s= After sorted by specified field (multiple fields can be specified), combinations of items specified in field f= are enumerated. k= List of key field name(s) (multiple fields can be specified) Compute combinations based on the list of key field name(s). -p Compute the permutations. -dup Output combinations with the same value.
Enumerate all combinations of two items in the item field for each customer, and save the output in item1,item2. Fields not specified at k=,f= (item field in this case) remains after the key field column.
$ more dat1.csv customer,item A,a1 A,a2 A,a3 B,a4 B,a5 $ mcombi k=customer f=item n=2 a=item1,item2 i=dat1.csv o=rsl1.csv #END# kgcombi a=item1,item2 f=item i=dat1.csv k=customer n=2 o=rsl1.csv $ more rsl1.csv customer%0,item,item1,item2 A,a3,a1,a2 A,a3,a1,a3 A,a3,a2,a3 B,a5,a4,a5
When you specify the -dup option, the output includes combination of the same field.
$ mcombi k=customer f=item n=2 a=item1,item2 i=dat1.csv o=rsl2.csv -dup #END# kgcombi -dup a=item1,item2 f=item i=dat1.csv k=customer n=2 o=rsl2.csv $ more rsl2.csv customer%0,item,item1,item2 A,a3,a1,a1 A,a3,a1,a2 A,a3,a1,a3 A,a3,a2,a2 A,a3,a2,a3 A,a3,a3,a3 B,a5,a4,a4 B,a5,a4,a5 B,a5,a5,a5
Enumerate permutation of two items in the item field for each customer, and save the output in column item1,item2.
$ mcombi k=customer f=item n=2 a=item1,item2 -p i=dat1.csv o=rsl3.csv #END# kgcombi -p a=item1,item2 f=item i=dat1.csv k=customer n=2 o=rsl3.csv $ more rsl3.csv customer%0,item,item1,item2 A,a3,a1,a2 A,a3,a2,a1 A,a3,a1,a3 A,a3,a3,a1 A,a3,a2,a3 A,a3,a3,a2 B,a5,a4,a5 B,a5,a5,a4