0

TCL プログラミングの初心者で、入力ファイルから一致する行を削除したい

  1. まったく同じ行内容
  2. パターン: "ghi\/\njkl\/\nrccu1" -> "Point \.*: 10 Sinks" \.* (単語「ポイント」の後ろの数字と「[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 のシンク" [色 = グレー] [スタイル = 固体] [重量 = 8];
"ghi\/\njkl\/\nrccu1" -> "ポイント 8: 10 のシンク" [色 = グレー] [スタイル = 固体] [重量 = 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 のシンク" [色 = グレー] [スタイル = 固体] [重量 = 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 に答える