TCL脚本将正则表达式与括号匹配并插入文本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TCL脚本将正则表达式与括号匹配并插入文本相关的知识,希望对你有一定的参考价值。
我有一个如下所述的输入文件
module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk
);
input a;
input ab;
input dhd;
input djdj;
input dhd;
output hdh;
output djjd;
output jdj;
output dk;
bist_reverse_mapper Umbist_reverse_inst( .BIST_SO(), .BIST_SO_ts1(), .BIST_SO_ts2(), .BIST_SO_ts3(), .BIST_GO(), .BIST_GO_ts1(),
.BIST_GO_ts2(), .BIST_GO_ts3(), .clk_mbist(), .BIST_SETUP(), .ltest_to_mcp_bounding_en(),
.MEM0_BIST_COLLAR_SI(), .MEM1_BIST_COLLAR_SI(), .MEM2_BIST_COLLAR_SI(), .MEM3_BIST_COLLAR_SI(),
.bistEn(), .BIST_COLLAR_DIAG_EN(), .ltest_to_en(), .BIST_EVEN_GROUPWRITEENABLE(),
.BIST_ODD_GROUPWRITEENABLE(), .BIST_SELECT(), .BIST_WRITEENABLE()
);
endmodule
我需要阅读此文件,然后在匹配正则表达式“ Umbist_reverse_inst(“]之后处理该文件以在字符串下方添加>
“。mbist_in,.mbist_out,”
而且我还必须将()删除到下面的实例bist_reverse_mapper Umbist_reverse_inst
输出文件应该像这样
输出文件
module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj; output dk; bist_reverse_mapper Umbist_reverse_inst(.mbist_in, mbist_out, .BIST_SO, .BIST_SO_ts1, .BIST_SO_ts2, .BIST_SO_ts3, .BIST_GO, .BIST_GO_ts1, .BIST_GO_ts2, .BIST_GO_ts3, .clk_mbist, .BIST_SETUP, .ltest_to_mcp_bounding_en, .MEM0_BIST_COLLAR_SI, .MEM1_BIST_COLLAR_SI, .MEM2_BIST_COLLAR_SI, .MEM3_BIST_COLLAR_SI, .bistEn, .BIST_COLLAR_DIAG_EN, .ltest_to_en, .BIST_EVEN_GROUPWRITEENABLE, .BIST_ODD_GROUPWRITEENABLE, .BIST_SELECT, .BIST_WRITEENABLE ); endmodule
我尝试过以下脚本以匹配正则表达式后插入文本。
set filename1 [glob -type f output_dir/mbist_wrapper/*input.sv ] # Read in the data; this is good even for pretty large files set f_1 [open $filename1] set lines [split [read $f_1] " "] close $f_1 set test_insert [ list ".mbist_in, .mbist_out,"] set REGEXP1 "Umbist_reverse_inst(" set idx1 [lsearch -regexp $lines $REGEXP1] if {$idx1 >= 0} { # Found something, so do the insert in the list of lines set lines1 [linsert $lines [expr {$idx1 + 1}] {*}$test_insert] # Write back to the file as we've made changes set f [open $filename1 "w"] puts -nonewline $f_1 [join $lines " "] close $f_1 }
但是执行此代码时出现错误
INSERTION> set idx1 [lsearch -regexp $lines $REGEXP1] // Error: couldn't compile regular expression pattern: parentheses () not balanced
以及如何在inst中删除(),如输出文件中所示
我有一个输入文件,如下所述模块bist_logic_inst(a,ab,dhd,dhdh,djdj,hdh,djjd,jdj,dhd,dhp,dk);输入一个输入ab;输入dhd;输入djdj;输入dhd;输出hdh;输出...
答案
嗨,我能够解决第一个问题,在匹配正则表达式之后插入文本
以上是关于TCL脚本将正则表达式与括号匹配并插入文本的主要内容,如果未能解决你的问题,请参考以下文章