You're replying to a comment by Henning.

Henning Permalink
April 07, 2013, 17:27

Power set:

$ cat set
a
b
c
$ eval echo {$(cat set | xargs -I{} echo -n \{{},\})}
{abc} {ab} {ac} {a} {bc} {b} {c} {}

or slightly shorter:

$ eval echo {$(cat set | xargs -I# echo -n \{#,\})}

Explanation:
I've got the idea when I saw the wonderful combinatorical feature mentioned under #6 in this article. First I found (after some tries) this which would give the desired result:

$ echo {{,a}{,b}{,c}}
{} {c} {b} {bc} {a} {ac} {ab} {abc}

(The outmost braces are nessesary for the empty set.) But here we manually type in the members of the set. To build the expression from the content of the file "set" I went the following steps:

$ cat set |xargs -I{} echo \{{},\}
{a,}
{b,}
{c,}

We need it in one line, so we append -n to echo:

cat set |xargs -I{} echo -n \{{},\}
{a,}{b,}{c,}

(We dont get a newline after that!)
To surround this with curly brackets we use command substition and another echo:

$ echo {$(cat set |xargs -I{} echo -n \{{},\})}
{{a,}{b,}{c,}}

With eval we ask the bash do brace expansion again:

$ eval echo {$(cat set |xargs -I{} echo -n \{{},\})}
{abc} {ab} {ac} {a} {bc} {b} {c} {}

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the first letter of your name: (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.