cat "$file" | sed -n ''$branch''p'' | sed 's/'$name'/&\n/g' | grep $name |wc -l
don't know whether it will gives you correct OP or not
What exactly you need ?..i mean your requirement.
You posted
where
$file=filename
$branch=line containing branch
$name=dev
but if you pass any numeric value for $brach say 1 or 2. The sed will print tht particular line and again some other searches and replaces. As always ther will be only one line , wc -l will result in 1.
How ever if u want to search for the existence of a word called "dev" in a specific line the following will do the job :
In this context of use "deroff -w" , the output is a word list, one ``word'' per line, with all other characters deleted.
I too not that much aware of it's use. From google i found that :
"Deroff reads each file in sequence and removes all nroff and troff(1) requests and non-text arguments, backslash constructions, and constructs of preprocessors such as eqn(1), pic(1), and tbl(1). Remaining text is written on the standard output"
If you are interested u can go through the link to find more about nroff and troff:
TEST>cat "$file" | sed -n ''$branch''p'' | deroff -w
branch
dev
sdf
dev
jin
kilii
fin
kale
boyle
dev
james
dev
TEST>cat "$file" | sed -n ''$branch''p'' | deroff -w | sort |uniq -c |grep $name | awk '{print $1>
4
Chk it once again the branch and name values your passing.