You may want to check Coccinele (http://coccinelle.lip6.fr/) instead of using `sed` here. See how I'm using it here #706.