title: search for string in text file in vb and print lines
body: <p>Hi I am new to VB and just though if someone could help me in my current scenario        </p>
  
  <p>I have a text file named shar.txt<br>
  It has 6 lines in it.        </p>
  
  <p>I am a new student<br>
  I am learning VB<br>
  Please help me friends<br>
  Friends always matter in our life<br>
  Thank You for your support<br>
  Always grateful to you            </p>
  
  <p>I want a script which reads this text file and look for the string such as "Friends", "support" and print the lines containing those strings in another text file at the same location say "sha.txt"        </p>
  
  <p>I tried till this point but lost my way i mid.        </p>
  
  <p>Please someone help me.<br>
  thanks    </p>
  
  <pre><code>Sub ReadToTextFile()
  Dim strPattern1 As String    
  Dim strPattern2 As String    
  H1 As String    
  H2 As String    
  strPattern1 = "friends"    
  strPattern2 = "support"    
  
  
  Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Users\sonu\Desktop\auto\shar.txt", 1, True)    
  Do Until
   objFileToRead.AtEndOfStream        
      strLine = objFileToRead.ReadLine        
      ElseIf 
  InStr(strLine, strPattern1) &gt; 0    
   Then        
          Wscript.Echo strLine    
                  H1 = strLine    
                  ElseIf 
  InStr(strLine, strPattern2) &gt; 0        
   Then        
                  Wscript.Echo strLine    
                  H2 = strLine    
             End If    
  
      End If    
  Loop    
  
  Wscript.Echo H2    
  
  Set objFileToRead = Nothing    
  
  End Sub    
  </code></pre>