It's not ruby but look at CRM114. It's like grep on sterroids andallows you to define begin and end blocks. Maybe you could shell outto it.