I have a php source code file and I want to add a line immediately following each line containing a function declaration. That's easy enough using sed and the /a\ command. But, that's not enough for me. I want to include in the appended text the name of the function. For the purpose of this exercise, I'll be satisfied with everything that is not 'function'
For example:
Code:
function UserLib($db) {
some other code;
}
would become:
Code:
function UserLib($db) {
debug("UserLib($db) {" )
some other code;
}
Questions is how do I get what remains after the match?
I tried this two-liner to match regions and use the resulting tokens, but they don't get substituted correctly in the output.
Code:
/\(function\) \(.*\)/a\
debug(\2)
and
/\(function\) \(.*\)/a\
debug("\2")
and
/\(function\) \(.*\)/a\
debug('\2')
I know I'm not the first one down this path. Is sed the correct tool?
Thanks