Q:

Bash: Loop a file until it reaches specific number of matching strings and start over

Edit: Long story short: I'm trying to count the amount of successful connections from a log file.  If it reaches 8, I need it run some command, then start over and count again. 
I try to loop through a file, and grep for a specific string, and count the lines of it with wc -l.  If it reaches 8 I need it to run a command, then start again from that point. 
Assuming I have a file like the example below:
I want to find "STRING" and if wc -l is equal to 8 I need to run a command and start over (append something and start from there) and count the other 8 that comes after them. 

STRING ...................
STRING ...................
STRING ...................
STRING ...................
STRING ...................
STRING ...................
...
I wrote this:

while true
do
countz=$(cat file.txt | grep "STRING" | wc -l)

echo $countz;

if [ "$countz" -eq 8 ];
        then #do_something
fi
done

A:

Not very clear what you want to achieve but
seq 100 | xargs -n 1 echo STRING \
| awk 'BEGIN { c=0; } $0 ~ /^STRING / {c++; if (c==8) { print "found"; c=0; } }' \
| your_command

This will execute your_command for every 8-th line
Or maybe you can count the total number of occurences of STRING in a file and dived it by 8 and then run that number of commands ? 
countz=(cat file.txt | grep "STRING" | wc -l)
total_runs=$[countz / 8]
for ((i=0;i<$total_runs;i++)); do your_command; done

UPDATE
Seems you want to edit log file. 
Easiest will be to create a new file with "delimiters"
awk 'BEGIN { c=0; } {
    print $0;
    if ($0 ~ /^STRING /) {
        c++;
        if (c==8) { print "your delimiter"; c=0; }
    }
 }' logfile > processed_logfile

