If the file and sections will be in the format that you posted, I have just worked out a more efficient way to do it.
Not using $readini though.
alias count_sections {
filter -cffgx $1 sections.tmp =|]
.remove sections.tmp
$iif($isid,return,echo -a) $calc($filtered + 1)
}
/usage /count_sections filename.ini