I know this question How to find patterns across multiple lines using grep? But I think my problem is more complicated. So I need help.
I have a dictionary file BCFile
as
boundary
{
inlet
{
type fixedValue;
value uniform (5 0 0);
}
outlet
{
type inletOutlet;
inletValue $internalField;
value $internalField;
}
....
}
I am writing a script so to print out the inlet
boundary condition fixedValue
, and the outlet
boundary condition inletOutlet
.
If I use cat BCFile | grep "type" | awk '{printf $2}' | tr -d ";"
, it won't work as keyword type
occurs many times.
If I use awk -v RS='}' '/inlet/ { print $4 }' BCFile
, it won't work either, because keyword inlet
also occurs many times.
I need a way to find pattern that first search for key word inlet
and then search the closest {
and }
.
Anyone knows how to do it smartly?