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

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -