0

我是 TCL 编程的初学者,想从匹配的输入文件中删除行

  1. 完全相同的行内容
  2. 模式:("ghi\/\njkl\/\nrccu1" -> "Point \.*: 10 Sinks" \.* 单词“Point”后面的数字和“ [color.*”后面的内容可以不同 - 所有其他需要完全匹配)
  3. "mno\/\npqr\/\nrccu1" -> "stu\/\nvwx\/\nrccu1" [label = "depth: 1"] [color=salmon] [fontcolor=salmon] [style=solid]; (单词“Point”后面的数字和“ [color.*”后面的内容可以不同-所有其他都需要完全匹配)

现在我有以下输入文件

"abc\/\ndef\/\nrccu1" [形状=八边形,颜色=红色,样式=填充];
"abc\/\ndef\/\nrccu1" [形状=八边形,颜色=红色,样式=填充];

"ghi\/\njkl\/\nrccu1" -> "第 1 点:10 个水槽" [color=salmon] [style=solid] [weight=8];
"123\/\n456\/\nrccu1" -> "第 9 点:10 个水槽" [color=grey] [style=solid] [weight=8];
"ghi\/\njkl\/\nrccu1" -> "第 8 点:10 个水槽" [color=grey] [style=solid] [weight=8];
"ghi\/\njkl\/\nrccu1" -> "第 13 点:20 个水槽" [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" [形状=八边形,颜色=红色,样式=填充];

"ghi\/\njkl\/\nrccu1" -> "第 1 点:10 个水槽" [color=salmon] [style=solid] [weight=8];
"123\/\n456\/\nrccu1" -> "第 9 点:10 个水槽" [color=grey] [style=solid] [weight=8];
"ghi\/\njkl\/\nrccu1" -> "第 13 点:20 个水槽" [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];
4

1 回答 1

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
于 2012-08-11T12:26:11.873 回答