I need to print the count of a matching string at the end of each line.
An example for matching foo
:
foo,bar,foo,foo
bar,foo,bar,bar
foo,foo,bar,bar
Result :
foo,bar,foo,foo,3
bar,foo,bar,bar,1
foo,foo,bar,bar,2
I have checked this link(How to count the number of a specific character in each line?) but no luck.
foobar
existed in a line should that be counted as matchingfoo
or not? What if the string to match wasfo.
andfox
existed in the line - should that count? You asked for a count of strings - you didn't say if it should be full or partial words but in any case at least some of the answers you got are counting partially matching regexps. – Ed Morton Sep 22 '21 at 22:18