How to count the number of lines in a text file starting with a specific word?
I do not want to use sed and then wc -l . Any better solution?
sed
wc -l
Try the following: -
awk '/^yourwordtofind/{a++}END{print a}' file
Just flatten your word and then use wc -l to count the lines ... like this grep '^your_word' /path/to/file | wc -l grep '^your_word' /path/to/file | wc -l
grep '^your_word' /path/to/file | wc -l
grep -c "pattern" <filename>
For example: if you want to find the more template in the test.txt file, then the command is given below:
more
test.txt
grep -c "more" test.txt