Hi experts,
I have following code:
Code:
for (int i=0; i<DimSum ;i++)
{
a[i] = new double [10];
}
for (int j=0; j<DimSum ;j++)
{
b[j] = x+y;
}
I want to search all such for loops where a "new" is present. I want to replace DimSum from all such loops with SumDim.
To search, I tried in vi (or in sed):
Code:
/for.*DimSum.*\n.*\n.*new
This works for the given search. But if the code is
Code:
for (int i=0; i<DimSum ;i++)
{
x = junk;//multiple lines before new
a[i] = new double [10];
}
then I need to search for any number of new line characters.
basically, I want ".*\n.*" to be searched any number of times until a "new" is found (thus I want to have a * after it) or a "}" is encountered . But I dont know how to group "\n.*" for the following * to take effect and to stop search if "}" is found.
Can anyone help me with this mess?
Regards
Thanks in Advance!