Use Perl to count the number of lines which see a zero surrounded on the left by a TAB and to the right by a word boundary, three times. In the end print the line count of such lines.
perl -lne '$c += 3 == (() = /\t0\b/g)}{print $c' file 7 Another way to do it is by looking at the fields:
perl -F'\t' -lane '$c++ if 3 == grep ! $_, @F[1..$#F]}{print $c' file Yet another way is to use the s///s/// command in a scalar context:
perl -lne '$c += s/\t0\b//g == 3}{print $c' file We use Gnu awk to do this:
awk -F'\t' ' { gsub(FS, FS FS) $0 = $0 FS if ($0 != gensub(FS"0"FS, "", 3, $0)) ++c } END{print c} ' file Gnu grep can also help you:
grep -cP '(.*\t0\b.*){3}' file