perl -lne 'sub out {print $h, "\n", scalar keys %c if %c } />/ and do { out(); %c =(); $h = $_ } or $c{$_}++; END { out() }' < input-file