Finding opening and closing braces

I am reading a cpp file thru shell script . There are many fuctions inside the cpp file

eg
pvvd_fncn_name1

{
..... something
}

pvvd_fncn_name2

{
..... something
}

what I require is a method to find the first opening brace and the coresponding last brace and search for a pattern in that part between braces ...

Pls help

Thanks and Regards

You can do the following way...

  1. Intially you can set the counter varaible to 0
  2. Whenevr you find a open brace increment the counter and store line number in a variable
  3. When you find Close braces decrement the counter and then check the value of counter.
  4. If the counter is zero, the print the strings in between starting line number and the closed braces (i.e count =0) and store it in a file.
  5. Then search pattern in the stored file.

any help appreciated ..I am new to scripting .. I also thought something like that only but couldnt implement it technically