title: How to search for word in text file and print part of line with Python?
body: <p>I'm writing a Python script. I need to search a text file for a word and then print part of that line. My problem is that the word will not be an exact match in the text file.</p>
  
  <p>For example, in the below text file example, I'm searching for the word <code>"color="</code>.</p>
  
  <p>Text File ex:</p>
  
  <pre><code>ip=10.1.1.1 color=red house=big
  ip=10.1.1.2 color=green house=small
  ip=10.1.1.3 animal = dog house=beach
  ip=10.1.1.4 color=yellow house=motorhome
  </code></pre>
  
  <p>If it finds it, it should print to a new text file <code>"color=color"</code>, not the whole line.</p>
  
  <p>Result Text File ex:</p>
  
  <pre><code>color=red
  color=green
  color=yellow
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>for line_1 in open(file_1):
      with open(line_1+'.txt', 'a') as my_file:
          for line_2 in open(file_2):
              line_2_split = line_2.split(' ')
              if "word" in line_2:
                  if "word 2" in line_2:
                      for part in line_2:
                          line_part = line_2.split(): #AttributeError: 'list' object has no attribute 'split'
                          if "color=" in line_part():
                              print(line_part)
  </code></pre>
  
  <p>I believe I need to use regular expressions or something like <code>line.find("color=")</code>, but I'm not sure what or how.</p>
  
  <p><strong>Question</strong>: How do I search a text file for a word (not an exact match) and the print only a specific part of each line?</p>