Reputation: 2726
Say I have a BCFile
having the following contents:
inlet
{
type fixedValue;
value uniform (5 0 0);
}
outlet
{
type inletOutlet;
inletValue $internalField;
value $internalField;
}
....
blahblahblah (other boundary condition with the same dictionary format as above)
In order to print out the type of outlet
boundary condition, that is inletOutlet
, I thought I could use,
cat BCFile | grep "type" | awk '{printf $2}' | tr -d ";"
But the problem now is in using grep
there are so many type
keyword appeared. So is there a way to first detect the word outlet
, then search and grep the contents between {}
? Thanks!
Upvotes: 0
Views: 340
Reputation: 111239
AWK is pretty powerful. For example if you set the record separator to }
each block becomes a record of its own. Then you just print the matching record:
$ awk -v RS='}' '/outlet/ { print $0 }' file
outlet
{
type inletOutlet;
inletValue $internalField;
value $internalField;
Upvotes: 1
Reputation: 1049
How about
grep -A 5 'outlet' BCFile | grep 'type' | awk '{printf $2}' | tr -d ";"
Upvotes: 0