Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question 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:

    PHP Code:
    function my_function() {


    PHP Code:
    function my_function() 

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

    Thank you!

  2. #2
    The sed part is easy.
    sed -e "s|{|\n{|g"
    Not sure about find.

  3. #3
    adding to what Cancerous has said:

    find . -type f -name "*.php" -exec sed -i.bak "s|{|\n{|g" {} \;
    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.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts