1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/gawk -f BEGIN { FS = "[|,]" } /\|/ { rules[$1][$2] = 1 } /,/ { delete seen for (i = 1; i <= NF; i++) { for (j in seen) { if (j in rules[$i]) next } seen[$i] = 1 } mid += $(i / 2) } END { print mid }