template: perm_subcluster
copy_cluster: yms_cfg_ref
allocations:
- type: cfgstore
hosts:
- {name: ymscfg-02.ops.bf1.yahoo.com, farm: east}
- {name: ymscfg-02.ops.gq1.yahoo.com, farm: west}
- type: aggregator
hosts:
- {name: ymsagg-08.ops.bf1.yahoo.com, farm: east}
- {name: ymsagg-10.ops.gq1.yahoo.com, farm: west}
- type: metricsdb
hosts:
- {name: ymsdb-11.ops.bf1.yahoo.com, farm: east}
- {name: ymsdb-11.ops.gq1.yahoo.com, farm: west}
上面的代码属于文件 temp.txt。另一个文件 tempo.pl 有一个 perl 标量变量 $pattern。$pattern 的值为:
- type: cfgstore
hosts:
- {name: ymscfg-02.ops.bf1.yahoo.com, farm: east}
- {name: ymscfg-02.ops.gq1.yahoo.com, farm: west}
- type: aggregator
hosts:
- {name: ymsagg-08.ops.bf1.yahoo.com, farm: east}
- {name: ymsagg-10.ops.gq1.yahoo.com, farm: west}
- type: metricsdb
hosts:
- {name: ymsdb-11.ops.bf1.yahoo.com, farm: east}
- {name: ymsdb-11.ops.gq1.yahoo.com, farm: west}
我想在 perl 或 sed 或 awk 或 regex 中编写一个代码块,它返回模板名称,即模板:perm_subcluster 如果 $pattern 的值与 temp.txt 中的行块匹配。