I have a text file and I would like to count for each line the number of appearances of a given word for example if the word is "text" and the file is
abc text fff text text jjj
fff fff text ddd
eee rrr ttt yyy
I expect the output
3
1
0
How can I achieve this with bash?
while read line; do echo "$line" |tr ' ' '\n' |grep text -c ; done < file
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments