0

假设我有BCFile以下内容:

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)

为了打印出outlet边界条件的类型,也就是inletOutlet我以为可以使用,

cat BCFile | grep "type" | awk '{printf $2}'  | tr -d ";"

但是现在的问题是在使用grep中出现了这么多的type关键字。那么有没有办法先检测单词outlet,然后搜索和grep之间的内容{}?谢谢!

4

2 回答 2

1

AWK 非常强大。例如,如果您将记录分隔符设置为}每个块成为它自己的记录。然后你只需打印匹配的记录:

$ awk -v RS='}' '/outlet/ { print $0 }' file
outlet
{
    type            inletOutlet;
    inletValue      $internalField;
    value           $internalField;
于 2013-04-04T23:06:29.740 回答
0

怎么样 grep -A 5 'outlet' BCFile | grep 'type' | awk '{printf $2}' | tr -d ";"

于 2013-04-04T22:54:25.693 回答