By the way, I mean any line with space delimiters.
Suppose a file test.txthas the following words, marked with spaces:
hello hello hello hell osd
hello
hello
hello
hellojames beroo helloooohellool axnber hello
way
how
I want to count the number of times the word hello appears on each line.
I used the command awk -F "hello" '{print NF-1}' test.txtto show the number of occurrences of the word hello on each line:
3
1
1
1
4
0
0
Thus, he finds a total of 3 + 1 + 1 + 1 + 4 = 10 occurrences.
The problem is in the fourth line: hello only 1 time as a separate word; words such as hellojames and helloooohellool should not be counted because greeting is not limited to spaces.
So, I want him to find 7 occurrences of hello as a separate word.
, 7 ?