Code:
awk '
NR==1 {print "Name", $0
CC = NF
for (i=1; i<2^CC; i++) Set[i] = 0
next
}
{for (i=1; i<=CC; i++) {T[$i]
R[$i,i] = 1
}
}
END {delete T[""]
for (t in T) {printf "%s", t
for (i=1; i<=CC; i++) printf ",%s", R[t,i]+0
printf RS
TMP = 0
for (i=1; i<=CC; i++) TMP = TMP + 2^(i-1)*R[t,i]
Set[TMP]++
}
for (i=1; i<2^CC; i++) {printf "Set"; for (j=0; j<CC; j++) if (int(i/2^j)%2) printf "%d", j+1; printf "=%d%s", Set[i], RS }
}
' FS=, file
Name,Set1,Set2,Set3,Set4,S5,S6
g1,1,1,1,1,1,1
g2,1,1,0,0,1,1
g3,0,0,1,0,1,1
g4,1,0,0,1,0,0
g5,1,1,1,1,1,1
g6,1,1,0,0,1,1
g7,0,1,0,1,1,0
g8,0,0,1,1,0,0
Set1=0
Set2=0
Set12=0
Set3=0
Set13=0
Set23=0
Set123=0
Set4=0
Set14=1
Set24=0
Set124=0
Set34=1
.
.
.
Set145=0
Set245=1
Set1245=0
.
.
.
Set256=0
Set1256=2
Set356=1
Set1356=0
.
.
.
Set23456=0
Set123456=2