With AWK in stead of SED this can be implemented without a loop. Just pipe the output of avr-size to AWK and have a three rules matching either section.