Is there a better way to grep until end of error message?

My file creates an output log after which includes a few sql queries.
I segregate them into warnings and errors and then get a total count.
The errors' and warnings' lines always start with SQL[0-9]{4}[A-Z] followed by the details of the error.

This is what im doing as o now...

errors=`grep -A 1 -E "^SQL3196N|^SQL3147N|^SQL3148W" $output.log`

This gets me only the first line after a match is obtained.

Some errors have 1 line and others stretch out to 10 lines...
How would do you capture this info for errors and warnings and later on count the number of distinct errors and warnings encountered???

I am closing this thread because it is a duplicate of a thread in Shell Programming and Scripting.