说我有一个BCFile
具有以下内容:如何使用shell脚本读取用户定义的字典?
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 {}
之间的内容?谢谢!
但是如果是'入口',因为关键字'入口'会出现很多次。此方法将不再起作用。 ( – Daniel 2013-04-05 03:07:35
有多种方法可以做到这一点:你可以将匹配条件从'/ outlet /'改为'/入口\ n {/',或者$ 1〜/入口/'或者'/ ^入口/ – Joni 2013-04-05 07:35:43