I have a folder named folder. Under folder I have two subfolders subfolder1 and subfolder2.
Both of these subfolders have the same text file file.txt.
That text file has following lines:
text
text
line
line
text text
text text
What I am trying to do with grep is to get the total count of text words but exclude text text words from the count.
If I run grep -ro "text" folder/ | wc -l | xargs echo "total matches :" I get the count of 12 but the result I am looking for is 4 because those two files have only two text words resulting to total of 4.
I have tried to run grep -ro "text" -v "text text" folder/ | wc -l | xargs echo "total matches :" and many other syntaxes with -v to exclude text text from the count with no success.
 
                        
It is easier to achieve it using awk , In short you want to print(count) the line where "text" appears only once :