Bash script which adds a line before every curly brackets

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:

function my_function() {



function my_function() 


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

Thank you!

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
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.