I'm working with a preprocessed C source file. I want to extract one function for additional processing. I can find the start of the particular function with:
gcc -DNDEBUG -march=native -E source.c > source.pre
BEGIN=$(grep -n 'static inline int some_function' source.pre | cut -f 1 -d ':')
After the above executes, I have a line number where the function begins. In this case, its 7812.
I am having trouble devising a way to capture the text between the C function's curly braces ({
and }
). Based on Extract middle section of lines of a text file, I think this is reducing to a problem of finding the immediate closing brace (}
).
How do find the immediate closing brace? Or how do I capture the text between curly braces in C preprocessed file?