I have been using grep with perl extension for multiline match .However it turns out that the line number of all the match depends on the number of lines in the first multiline match !
The grep regex to find the c function start :
grep -iPn '^[^\S\n]*?\w+\s+\w+?\s*\([\w-0-9,/* \s]*\)\s*\{$'
I can explain better with an example :
Suppose these two function exists in the source file
int f1(int a) {
int
f2 (int b )
{
In this case ,the grep matches the regex successfully and the line number output to stdout is in par with the line number of the source file .
The problem arises when a multiline function comes first .This alters the line number output and after examining the file for some time I came to a conclusion. The multiline functions are matched but read as a single line by the grep therefore it assigns the whole function a single line number.The next line that follows the function gets its line number short depending on the number of lines the ‘function definition start regex ‘occupies.
There are numerous multiline C functions in my file and the line number is way too deviated for each one of them.
Is there a way to correct this ?
Using the pcregrep for the same regex shows the correct line number !