fork(3) download
  1. #!/bin/bash
  2. # http://stackoverflow.com/questions/28942535/bourne-shell-split-string-according-to-multiple-criteria-iptables-multiport-li
  3. awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0;
  4. if (r ~ /([^,]*,){6}/) { print r; r=""; } next }
  5. { s=(s ? s "," : "") $0;
  6. if (s ~ /([^,]*,){14}/) { print s; s=""; } }
  7. END { if (r && s) {
  8. p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } }
  9. if (r) print r; if (s) print s }'
Success #stdin #stdout 0s 5876KB
stdin
21:22,23:24,25:26,27:28,29,30:40,60:61,62:63,64:65,70
stdout
21:22,23:24,25:26,27:28,30:40,60:61,62:63
64:65,29,70