Removing first defined function in bashrc

74 Views Asked by At

I have a file containing:

...
function myfunction(){
                            content
    }
...
function myfunction(){
                            content2
    }
...

How can I automatically remove the first occurrence of myfunction for every such duplica function?

1

There are 1 best solutions below

0
On

You can remove local .bashrc functions with sed.

For example, to remove func1() and func2(), and keep a backup of .bashrc:

sed -i.bak -e '/^func1 (/,/}$/d' -e '/^func2 (/,/}$/d' ~/.bashrc

Note that it will remove simple functions that includes one block of { ... }. If you have inner { ... } blocks, extend the regexp accordingly.