title: Groovy: editing a file
body: <p>I have a sample file like the following:</p>
  
  <pre><code>CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11
  (
  asdfa
  )
  CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11
  (
  asdfas
  )
  
  some other text in file
  </code></pre>
  
  <p>I want to convert this file into following:</p>
  
  <pre><code>CREATE GLOBAL TEMPORARY TABLE 1
  (
  asdfa
  )
  CREATE GLOBAL TEMPORARY TABLE 2
  (
  asdfas
  )
  
  some other text in file
  </code></pre>
  
  <p>So basically every TEMPORARY TABLE occurrence will have number appended to it. </p>
  
  <p>So far I have the following groovy script:</p>
  
  <pre><code>int i = 0
  new File ("C:\\Not_Modified").eachFile{file -&gt;
          println "File name: ${file.name}"
          new File ("C:\\Not_Modified\\"+file.name).eachLine {line -&gt;
                  if (line.indexOf("TEMPORARY TABLE")&gt;0)
                  {
                      i++
                  }
              }
          println "There are ${i} occurences of TEMPORARY TABLE"
      }
  </code></pre>
  
  <p>How can I change the text in the file? should I be writing to a different file?</p>
  
  <p>btw, I have directory in my script because I will be working on lot of these type of files in a directory.</p>
  
  <p>I should have opted perl for this task but wanted to give groovy a try. </p>