我是编程TCL的初学者,想要从匹配
的输入文件中删除行"ghi\/\njkl\/\nrccu1" -> "Point \.*: 10 Sinks" \.*
(单词“Point”后面的数字和“[color.*
”后面的内容可能不同 - 所有其他内容都需要完全匹配)"mno\/\npqr\/\nrccu1" -> "stu\/\nvwx\/\nrccu1" [label = "depth: 1"] [color=salmon] [fontcolor=salmon] [style=solid];
(单词“Point”后面的数字和“[color.*
”后面的内容可能不同 - 所有其他内容都需要完全匹配)现在我有以下输入文件
"abc\/\ndef\/\nrccu1" [shape=octagon,color=red,style=filled]; "abc\/\ndef\/\nrccu1" [shape=octagon,color=red,style=filled]; "ghi\/\njkl\/\nrccu1" -> "Point 1: 10 Sinks" [color=salmon] [style=solid] [weight=8]; "123\/\n456\/\nrccu1" -> "Point 9: 10 Sinks" [color=grey] [style=solid] [weight=8]; "ghi\/\njkl\/\nrccu1" -> "Point 8: 10 Sinks" [color=grey] [style=solid] [weight=8]; "ghi\/\njkl\/\nrccu1" -> "Point 13: 20 Sinks" [color=grey] [style=solid] [weight=8]; "mno\/\npqr\/\nrccu1" -> "stu\/\nvwx\/\nrccu1" [label = "depth: 1"] [color=salmon] [fontcolor=salmon] [style=solid]; "mno\/\npqr\/\nrccu1" -> "stu\/\nvwx\/\nrccu1" [label = "depth: 4"] [color=salmon] [fontcolor=salmon] [style=solid]; "mno\/\npqr\/\nrccu1" -> "stu\/\nvwx\/\nrccu1" [label = "depth: 1"] [color=grey] [fontcolor=red] [style=solid];
输出文件应包含:
"abc\/\ndef\/\nrccu1" [shape=octagon,color=red,style=filled]; "ghi\/\njkl\/\nrccu1" -> "Point 1: 10 Sinks" [color=salmon] [style=solid] [weight=8]; "123\/\n456\/\nrccu1" -> "Point 9: 10 Sinks" [color=grey] [style=solid] [weight=8]; "ghi\/\njkl\/\nrccu1" -> "Point 13: 20 Sinks" [color=grey] [style=solid] [weight=8]; "mno\/\npqr\/\nrccu1" -> "stu\/\nvwx\/\nrccu1" [label = "depth: 1"] [color=salmon] [fontcolor=salmon] [style=solid]; "mno\/\npqr\/\nrccu1" -> "stu\/\nvwx\/\nrccu1" [label = "depth: 4"] [color=salmon] [fontcolor=salmon] [style=solid];
答案 0 :(得分:0)
set in [open input.file r]
array set seen {}
while {[gets $in line] != -1} {
# blank lines should be printed as-is
if {[string length [string trim $line]] == 0} {
puts $line
continue
}
# create the "key" for this line
regsub {\mPoint \d+} $line {} key
regsub {\mcolor=\w+} $key {} key
# print the line only if the key is unique
if { ! [info exists seen($key)]} {
puts $line
set seen($key) true
}
}
close $in