Chinaunix
标题:
字符的各种排列组合
[打印本页]
作者:
soccer
时间:
2012-11-02 12:49
标题:
字符的各种排列组合
本帖最后由 soccer 于 2014-09-03 20:03 编辑
有若干字符, a b c
通过shell实现字母的各种组合.
a
b
c
ab
ac
bc
....
....
求指导,谢谢啦
https://ftp.emc.com/action/login ... password=x6AAxqABix
作者:
mcshell
时间:
2012-11-02 14:02
echo {a,b,c}{a,b,c}
复制代码
作者:
jason680
时间:
2012-11-02 14:24
本帖最后由 jason680 于 2012-11-02 14:32 编辑
回复
1#
soccer
$ cat select.sh
echo "a b c" |
awk '
# t = total ,ex: 3
# g = get ,ex: 1,2,3
# c = count
# p = prefix
# a = array ,ex:(a b c )
function x(t,g,c,p,a,n,r){
if(g==1){
r="";
for(n=c+1;n<=t;n++)
r=r""p""a[n]"\n"
}
else{
for(n=c+1;n<=t-g+1;n++)
r=r""x(t,g-1,++c,p""a[n],a);
}
return r
}
{t=split($0,a," ");for(g=1;g<=t;g++)printf x(t,g,0,"",a)}'
$ bash select.sh
a
b
c
ab
ac
bc
abc
作者:
soccer
时间:
2012-11-02 15:23
mcshell 发表于 2012-11-02 14:02
这个牛,不过这只包括一种情况,就是任何组合都是2个字符,不包括3个字符的组合。
作者:
dn833
时间:
2012-11-02 15:28
echo {a..c}{a..c}
复制代码
作者:
soccer
时间:
2012-11-02 16:51
dn833 发表于 2012-11-02 15:28
有没有既包括2个字符和3个字符的啊。
作者:
dn833
时间:
2012-11-02 17:27
回复
6#
soccer
echo {a..c} {a..c}{a..c} {a..c}{a..c}{a..c}
复制代码
那是这样的???
作者:
hbmhalley
时间:
2012-11-02 19:46
本帖最后由 hbmhalley 于 2012-11-02 19:50 编辑
dc -e '2o2 4^[1-pd0<t]dstx' | sed -r "s/$/ `echo {a..d}`,/;:1 s/([01])([^01]*) (.),/\2,\1\3/;t1;s/.*,|0.|1//g"
复制代码
这样?
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2