user2517676 user2517676 - 2 months ago 8
Linux Question

Counting lines starting with a certain word

How to count the number of lines in a text file starting with a certain word?
I do not want to use

"sed"
and then
"wc -l"
. Any better solution?

Answer

Try this:-

  awk '/^yourwordtofind/{a++}END{print a}' file