bash - How to count the number of appearances of a word in each line -


i have text file , count each line number of appearances of given word example if word "text" , file

abc text fff text text jjj fff fff text ddd eee rrr ttt yyy 

i expect output

3 1 0 

how can achieve bash?

while read line; echo "$line" |tr ' ' '\n' |grep text -c ; done < file  

Comments

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -