title: Search and Replace Text in CSV file using Python
body: <p>I just started with Python 3.4.2 and trying to find and replace text in csv file.</p>
  
  <p>In Details, <code>Input.csv</code> file contain below line:</p>
  
  <pre><code>0,0,0,13,.\New_Path-1.1.12\Impl\Appli\Library\Module_RM\Code\src\Exception.cpp
  
  0,0,0,98,.\Old_Path-1.1.12\Impl\Appli\Library\Prof_bus\Code\src\Wrapper.cpp
  
  0,0,0,26,.\New_Path-1.1.12\Impl\Support\Custom\Vital\Code\src\Interface.cpp
  
  0,0,0,114,.\Old_Path-1.1.12\Impl\Support\Custom\Cust\Code\src\Config.cpp
  </code></pre>
  
  <p>I maintained my strings to be searched in other file named <code>list.csv</code></p>
  
  <pre><code>Module_RM
  Prof_bus
  Vital
  Cust
  </code></pre>
  
  <p>Now I need to go through each line of <code>Input.csv</code>and replace the last column with the matched string.</p>
  
  <p>So my end result should be like this:</p>
  
  <pre><code>0,0,0,13,Module_RM  
  0,0,0,98,Prof_bus  
  0,0,0,26,Vital  
  0,0,0,114,Cust  
  </code></pre>
  
  <p>I read the input files first line as a list. So text which i need to replace came in <code>line[4]</code>. I am reading each module name in the <code>list.csv</code> file and checking if there is any match of text in <code>line[4]</code>. I am not able to make that <code>if</code> condition <code>true</code>.  Please let me know if it is not a proper search.</p>
  
  <pre><code>import csv
  import re  
  
  with open("D:\\My_Python\\New_Python_Test\\Input.csv") as source, open("D:\\My_Python\\New_Python_Test\\List.csv") as module_names, open("D:\\My_Python\\New_Python_Test\\Final_File.csv","w",newline="") as result:
  reader=csv.reader(source)
  module=csv.reader(module_names)
  writer=csv.writer(result)
  #lines=source.readlines()
  for line in reader:
  for mod in module_names:
      if any([mod in s for s in line]):
          line.replace(reader[4],mod)
          print ("YES")
      writer.writerow("OUT")
      print (mod)
  module_names.seek(0)
  lines=reader
  </code></pre>
  
  <p>Please guide me to complete this task.</p>
  
  <p>Thanks for your support!</p>