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
Post a Comment