I try to grep some string and want grep to stop at a '+' symbol. The searched string could be "foo" or "foo+bar". Grep treats all findings no matter what comes after foo and the -w option seems recognizing the '+' as whole word also. So I want to grep all files that include matches with 'foo' but not handle matches like 'foo+bar'. The command should be stored in a varaible like this
COUNT="$(find . -maxdepth 1 -type f -name '*.sh' | xargs grep -w -o -m 1 "foo" | wc -l)"
So how does this var has to be modified to only find the foo entries in the files but not foo+bar.
EDIT: Finally I have the solution for my case. Maybe I did not describe clearly enough what I needed but the trick was to add a ^ at beginning and a $ at the end of the searched string. So my files in the folder that could contain something like text=foo or text=foo+bar should be filtered so when I search for text=foo grep only outputs these and not including text=foo+bar. My code now looks like
COUNT="$(find . -maxdepth 1 -type f -name '*.sh' | xargs grep -x -o -m 1 "^text=foo$" | wc -l)"
And now in that case grep doesnt count findings with text=foo+bar. Sounds as simple as it is but needed again some struggle for me to figure out :)