Given the string: lolololololol
Grep will not overlap match when I try to find the number of lol
's.
echo "lolololololol" | grep -o 'lol' | wc -l
The above snippet returns 3
. When in fact the answer I would like is that there are 6
lol
's. For this case I know I could simply grep for lo
, but this example is meant to represent the general question of how allow grep or some other search tool to find overlapping matches.
Other examples
echo "1 2 3 4 5" | grep -E '(^| )[0-9]( |$)'
echo "10101" | grep '101'
The best solution can be found at https://unix.stackexchange.com/questions/276159/grep-that-works-with-overlapping-patterns