Count number of occurrence at each line

Hi

I have the following file

ENST001 ENST002 4 4 4 88 9 9
ENST004 3 3 3 99 8 8
ENST009 ENST010 ENST006 8 8 8 77 8 8 

Basically I want to count how many times ENST* is repeated in each line so the expected results is

2
1
3

Any suggestion please ?

Hi

$ awk '{for(i=1;i<=NF;i++)if($i ~ /^ENST/)x++;print x;x=0}' file
2
1
3

Guru.

1 Like
perl -lne 'print s/ENST//g' file
1 Like
awk '{n=gsub(/ENST/,'ENST',$0);print n}' file
awk -FENST '{print NF-1}' file
awk '{print gsub(/ENST/,x)}' infile