title: In Tcl, how to read in file by line and find a list of string (from another file) then append the line with a ##
body: <p>I need to be able tp read in  file by line and find a set of strings (from another file) that starts with the strings plus set of characters like ({ somedata }) then append the line with a ## to that block. </p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>set mydir &lt;path to my dir&gt;
  #file name file.txt with content:
  ~&gt;cat file.txt
  Strng00  {
     some data 
  }
  
  Strng021  {
     some data 
  }
  
  Strng02  {
     some data 
  }
  
  Strng03  {
     some data 
  }
  
  Strng_dt  {
     some data 
  }
  
  Strng01 {
     some data 
  }
  Strng02  {
     some data 
  }
  
  Strng03  {
     some data 
  }
  
  Strng_dt  {
     some data 
  }
  
  Strng42  {
     some data 
  }
  
  Strng412 
  -- 
  set list { Strng01 Strng02 Strng03 Strng_dt Strng42 } # May be read in the list from another file which needs to be matched
  set fileIn [lindex $argv 0]
  set fileInId  [open $mydir/file.txt r]
  set appendLine 0
  foreach item $list {
      set j 0
      while {[gets $fileInId line ] != -1} {
          if [regexp  -all -line $item $line] { set appendLine 1 } 
          if $appendLine {
              if [regexp {^\s*\}\s*$} $line] { set appendLine 0 }   
              set line "## $line"    
          }
          puts $line
      }
  set j 1
  }
  </code></pre>
  
  <p>The result only shows the first entry of the list:</p>
  
  <pre><code>Strng00 
  Strng021 
  Strng02 
  Strng03 
  Strng_dt 
  ##Strng01  {
  ##   some data  
  ##}
  
  Strng02 
  Strng03 
  Strng_dt 
  Strng42 
  </code></pre>
  
  <h2>    Strng412</h2>
  
  <p>I'd like to get ## after each of the items listed..
  Thanks in advance.`   </p>