I would like to search for simple statements ifin a collection of C source files.
These are expressions of the form:
if (condition)
statement;
Any number of spaces or other sequences (for example, "} else") may appear on the same line before if. Comments may appear between "if (condition)" and "statement;".
I want to exclude compound form expressions:
if (condition)
{
statement;
statement;
}
I tried each of the following in awk:
awk '/if \(.*\)[^{]+;/ {print NR $0}' file.c
awk '/if \(.*\)[^{]+/ {print NR $0}' file.c
awk '/if \(.*\)/ {print NR $0}' file.c
(B) and (C) give different results. Both include the elements that I am looking for and the elements that I want to exclude. Part of the problem, obviously, is how to deal with patterns that span multiple lines.
( , ..) .
?