title: Search for a word in file & print the matching line - Python
body: <p>I am newbie to Python, and I am trying to find a word in the file and print the "entire" matching line </p>
  
  <p>The exmaple.txt has following text:</p>
  
  <pre><code>sh version
  
  Cisco IOS Software, 2800 Software (C2800NM-IPBASE-M), Version 12.4(3h), RELEASE SOFTWARE (fc2)
  
  sh inventory
  
  NAME: "2811 chassis", DESCR: "2811 chassis, Hw Serial#: FHK1143F0WY, Hw 
  NAME: "High Speed Wan Interface card with 16 RS232 async ports(HWIC-16A)", 
  NAME: "High Speed Wan Interface card with 16 RS232 async ports(HWIC-16A)", 
  NAME: "16 Port 10BaseT/100BaseTX EtherSwitch"
  </code></pre>
  
  <p>Requirement : 
  To find the string "Cisco IOS Software" and if found print that complete line.
  Find "NAME:" in the file and if found print that complete line &amp; count the number of occurrences</p>
  
  <p>Code:</p>
  
  <pre><code>import re
  def image():
      file = open(r'C:\Users\myname\Desktop\Python\10_126_93_132.log', 'r')
      for line in file:
          if re.findall('Cisco IOS Software', line) in line:
              print(line)
          else:
              print('Not able to find the IOS Information information')
  
  def module():
      file = open(r'C:\Users\myname\Desktop\Python\10_126_93_132017.log', 'r')
      for line in file:
          if re.findall('NAME:') in line:
              print(line)
          else:
              print('No line cards found')
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:/Users/myname/Desktop/Python/copied.py", line 19, in &lt;module&gt;image()
  File "C:/Users/myname/Desktop/Python/copied.py", line 5, in image if re.findall('Cisco IOS Software', line) in line:
  TypeError: 'in &lt;string&gt;' requires string as left operand, not list
  </code></pre>