awk 'BEGIN{ RS="</cisco:name>"} { m=split($0,a,"\n") f=0 for(i=1;i<=m;i++) { if(a[i] ~ /<cisco:cpt>/){ f++ } } print f }' file