title: Copy some lines in a file to another file using vbscript
body: <p>I am a novice to VB scripting and was trying to work on a file handling. </p>
  
  <p>I was trying to write a script which reads an xml file and copies all data between the <code>&lt;Text&gt;</code> and <code>&lt;/Text&gt;</code> tags to a new file. This should happen for all <code>&lt;Text&gt;</code> and <code>&lt;/Text&gt;</code> sections in the file. </p>
  
  <p>My text file is as follows.</p>
  
  <pre><code>&lt;Text&gt;    M3XAUDT-A           FILE M30000            --- AUDIT TRAIL STATISTICS ---     RUN   TUESDAY 07/02/02 AT 23:21     PAGE    1
                                              RECORD COUNTS FOR CAE ON FILE M2AUD
  
  &lt;/Text&gt;
  &lt;/Page&gt;
  &lt;Page&gt;
  &lt;Text&gt;    M3XAUDT-A           FILE M30000            --- AUDIT TRAIL STATISTICS ---     RUN   TUESDAY 07/02/02 AT 23:21     PAGE    2
                                              RECORD COUNTS FOR CAE ON FILE M3AUD
  &lt;/Text&gt;
  &lt;/Page&gt;
  &lt;Page&gt;
  &lt;Text&gt;    M3XAUDT-A           FILE M30000            --- AUDIT TRAIL STATISTICS ---     RUN   TUESDAY 07/02/02 AT 23:21     PAGE    3
                                              RECORD COUNTS FOR CAE ON FILE M2AUD
  &lt;/Text&gt;
  </code></pre>
  
  <p>Before i would start creating a new file to copy the sections, i thought I could see whether the right data has been picked up using a msgbox. </p>
  
  <p>I tried with the below script, but it fails by going into a loop after displaying the 1st line. </p>
  
  <pre><code>Dim fso2, objStream2, strline, strline1,
  
  set fso2=Createobject("Scripting.FileSystemObject")
  if fso2.fileExists("C:\Harsha\1_Test\Source\APE_new.xml") then
  set objStream2 = fso2.OpenTextFile("C:\Harsha\1_Test\Source\APE_new.xml")
  i=1
  do while not objStream2.AtEndOfStream
          strline= strline &amp; objStream2.Readline &amp;vbNewLine
          do while instr(strline,"&lt;Text&gt;") 
                  strline1=strline1&amp;objStream2.Readline &amp;vbNewLine
                  msgbox strline1
          do until instr(strline1,"&lt;/Text&gt;") 
          strline2=strline2&amp;strline1
          loop
              msgbox strline2
          loop
  loop
  
  end if
  ObjStream2.close 
  </code></pre>
  
  <p>Thank you for your help in advance. </p>