Bash script which adds a line before every curly brackets

Hello,
I need to create a bash script that adds a row before every curly bracket for functions, classes (classes and methods) and try/catch blocks in PHP code.

I think using the program in conjunction with sed
E.G. : find . -type f \( -name "*.php \) -exec sed …

For example:


<?php
function my_function() {

}

Becomes:


<?php
function my_function() 
{

}

Can you help me so that I can achieve this, please?

Thank you!

Hi,
Not much good at Bash, but this would be quite simple in Ruby.
Do you have access to Ruby?

Might be worth looking at this http://phptidy.berlios.de/
or php beautifier

There’s several IDEs out there that have code formatting scripts. I believe Eclipse is one of them, though I’m not sure if you can customize it to what you want.