title: Using grep in python
body: <p>There is a file (query.txt) which has some keywords/phrases which are to be matched with other files using grep. The last three lines of the following code are working perfectly but when the same command is used inside the while loop it goes into an infinite loop or something(ie doesn't respond).</p>
  
  <pre><code>import os
  
  f=open('query.txt','r')
  b=f.readline()
  while b:
      cmd='grep %s my2.txt'%b    #my2 is the file in which we are looking for b
      os.system(cmd)
      b=f.readline()
  f.close()
  
  a='He is'
  cmd='grep %s my2.txt'%a
  os.system(cmd)
  </code></pre>