我在TCL脚本新手。 只是希望在这里得到专家的一些建议。
我希望处理与如下格式的报表。 我想打印的报告没有标题,并用像刚才单行 -
Connections for net 'pmg_ccu_ot2_tam_50mhz_sel_xainfwh' :: Driver a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par) :: Load b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par)
Connections for net 'pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2' :: Driver d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par) :: Load e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Input Pin (e_par), f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par)
<more . . .>
很感激,如果任何人都可以给予一定的光线和想法给我。 非常感谢!
****************************************
Report : net
-connections
Design : soc
Version: G-2012.06-SP2
Date : Sun Apr 7 22:56:33 2013
****************************************
Connections for net `pmg_ccu_ot2_tam_50mhz_sel_xainfwh`:
Driver Pins Type
------------ ----------------
a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par)
Load Pins Type
------------ ----------------
b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par)
1
Connections for net `pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2`:
Driver Pins Type
------------ ----------------
d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par)
Load Pins Type
------------ ----------------
e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (e_par)
f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par)
1
<more . . .>
如果我理解正确你的要求,我会做这样的事情:
输入文件包括:
****************************************
Report : net
-connections
Design : soc
Version: G-2012.06-SP2
Date : Sun Apr 7 22:56:33 2013
****************************************
Connections for net `pmg_ccu_ot2_tam_50mhz_sel_xainfwh`:
Driver Pins Type
------------ ----------------
a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par)
Load Pins Type
------------ ----------------
b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par)
1
Connections for net `pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2`:
Driver Pins Type
------------ ----------------
d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par)
Load Pins Type
------------ ----------------
e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (e_par)
f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par)
1
<more . . .>
剧本:
# Read file containing input
set inputfile [open "inputfile.txt" r]
# File where output will be written in
set outputfile [open "outputfile.txt" w]
# $type will contain the Pin Type and $outputline will contain the final
# line to be written
set type ""
set outputline ""
# Read each line in the inputfile
while {[gets $inputfile line] != -1} {
# If first word in line is "Connections" execute
if {[lindex [split $line " "] 0] == "Connections"} {
# If $outputline not empty while in this if, it means that we have
# reached a new connection. So print out the current connection
# after joining all its elements by " :: " and reset the output line.
if {$outputline != ""} {
puts $outputfile [join $outputline " :: "]
set outputline ""
}
# Replacing the ` by ' and removing the end ":" and then putting
# the full thing into $output line as an element of a list
regsub -all {\`} $line "\'" newline
set newline [string trimright $newline "\:"]
lappend outputline $newline
}
# If there is "Pins" in the line, this means we have a header. The regexp
# captures the pin type by looking for any alphanumeric characters before
# "Pins"
regexp -- {([\w]+) Pins} $line - type
# If there is " Pin " in the line, it means we are in a row of the
# different 'Pins' type. Here, we put the while line after removing
# the extra white spaces into the $outputline list.
if {[regexp -- { Pin } $line]} {
lappend outputline "$type [string trim $line]"
}
}
# We reached the end of the document. So, add the last line into the outputfile.
puts $outputfile [join $outputline " :: "]
# Close the files we opened.
close $inputfile
close $outputfile
输出:
Connections for net 'pmg_ccu_ot2_tam_50mhz_sel_xainfwh' :: Driver a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par) :: Load b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par)
Connections for net 'pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2' :: Driver d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par) :: Load e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (e_par) :: Load f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par)
该脚本将在他们来的任何命令“驱动程序类型”或“加载类型”(你可以添加新类型以及)。 有没有在你输入你的任何其他可能的变化?
编辑:您可以更改switch
块到这一点,它会采取任何类型的Pins
if {[regexp -- {([\w]+) Pins} $line - type]} {
set counter 0
}
重新编辑:添加--
在正则表达式。
rereEDIT:问题匹配的编辑。