Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-25-2012 #1
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:
Becomes:PHP Code:<?php
function my_function() {
}
Can you help me so that I can achieve this, please?PHP Code:<?php
function my_function()
{
}
Thank you!
- 10-25-2012 #2Just Joined!
- Join Date
- May 2012
- Posts
- 43
The sed part is easy.
Not sure about find.Code:sed -e "s|{|\n{|g"
- 10-25-2012 #3Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,689
adding to what Cancerous has said:
you can remove the "-i.bak" part, if you are not paranoid and do not want to create backup copies of all files that sed edits.Code:find . -type f -name "*.php" -exec sed -i.bak "s|{|\n{|g" {} \;


Reply With Quote
