In want to replace a function in a file by another. I have this :
File1.cpp:
void Component::initialize()
{
my_component = new ComponentClass();
}
and File2.cpp:
void Component::initialize()
{
if (doInit)
{
my_component = new ComponentClass();
}
else
{
my_component.ptr = null;
}
}
I've try to write a script but my grep does not provide a result :
Old=$(grep -Eo "void Component::initialize(\n|.)*(^})*?" file1.cpp)
echo "Old=$Old" # empty variable
# My purpose is to do this :
New=$(grep -Eo "void Component::initialize(\n|.)*(^})*?" file2.cpp)
sed -i "s/$Old/$New/g" file1.cpp