【发布时间】:2022-12-19 17:45:44
【问题描述】:
我有以下格式的文件
addInst -inst RESET_n_RS -cell PRWD_V ; placeInstance RESET_n_RS 4653.84 10212 R180
addInst -inst MODE_RS -cell PRWD_V ; placeInstance MODE_RS 4686.864 10212 R180
addInst -inst VDD_PD_T_4 -cell PVDD1_V ; placeInstance VDD_PD_T_4 4719.888 10212 R180
addInst -inst VDD_IO_PD_T_5 -cell PVDD2_V ; placeInstance VDD_IO_PD_T_5 4785.888 10212 R180
placeInstance DBG_RS 4861.728 10212 R180
placeInstance HAST_RS 4894.752 10212 R180
addInst -inst VDD_PD_T_8 -cell PVDD1_V ; placeInstance VDD_PD_T_8 4927.776 10212 R180
placeInstance WIRE_RS 4993.776 10212 R180
addInst -inst EN0_RS -cell PRWD_V ; placeInstance EN0_RS 5026.8 10212 R180
如果行有PRWD_V 模式,我想为该行打印$2,如果在该行中找不到模式,则不要按原样打印该行。
输出如下:
placeInstance RESET_n_RS 4653.84 10212 R180
placeInstance MODE_RS 4686.864 10212 R180
addInst -inst VDD_PD_T_4 -cell PVDD1_V ; placeInstance VDD_PD_T_4 4719.888 10212 R180
addInst -inst VDD_IO_PD_T_5 -cell PVDD2_V ; placeInstance VDD_IO_PD_T_5 4785.888 10212 R180
placeInstance DBG_RS 4861.728 10212 R180
placeInstance HAST_RS 4894.752 10212 R180
addInst -inst VDD_PD_T_8 -cell PVDD1_V ; placeInstance VDD_PD_T_8 4927.776 10212 R180
placeInstance WIRE_RS 4993.776 10212 R180
placeInstance EN0_RS 5026.8 10212 R180
我尝试使用 awk
awk -F';' '{for (i=1;i<=NF;i++) if ($i ~ /PRWD_V/) print $2} {print $1,$2}' file1
这仅适用于某些行,输出不正确。
我们也可以在TCL做同样的事情吗?
【问题讨论】: