Aqui está um script Python que faz o que você quer:
#!/usr/bin/env python2
# -*- coding: ascii -*-
"""eche.py"""
import csv
from collections import OrderedDict
# Open the first file
with open("eche", 'r') as csvfile1:
csvreader1 = csv.reader(csvfile1, delimiter=',')
# Skip the header row
next(csvreader1, None)
# Read the data into a dictionary,
# indexed by the value of the first column
rows1 = OrderedDict((row[0], row) for row in csvreader1)
# Open the second file
with open("eche.txt", 'r') as csvfile2:
# Read the data into a dictionary,
# indexed by the value of the first column
rows2 = {row[0]: row for row in csv.reader(csvfile2, delimiter=',')}
# Iterate through the rows of the first file
for key, row in rows1.iteritems():
# If the key from the first file matches a row in the second file,
# output the updated row
if key in rows2:
print(','.join(row[0:3] + [rows2[key][1]]))
# If the key from the first file does NOT match
# a row in the second file then output the row unchanged
else:
print(','.join(row))
A execução deste script com seus dados de exemplo produz a seguinte saída:
VC76,0.10000000E+00,0.2837726135782E+08,207.64 1K02,0.10000000E+00,0.2837950666778E+08,0.6757007619124E+02 P476,0.10000000E+00,0.2837975332748E+08,241.06 KG76,0.10000000E+00,0.2838117264779E+08,284.31 1K05,0.10000000E+00,0.2610647023303E+08,0.1841342000212E+03 1K06,0.10000000E+00,0.2611103965949E+08,0.1845191988294E+03 1K07,0.10000000E+00,0.2611275589639E+08,0.1845173169920E+03 1K08,0.10000000E+00,0.2611346615238E+08,0.1846393014710E+03 VC37,0.10000000E+00,0.2611374063470E+08,177.33 1K10,0.10000000E+00,0.2610224473371E+08,0.1835417139884E+03 M037,0.10000000E+00,0.2611370504845E+08,263.58 KG37,0.10000000E+00,0.2611331725657E+08,283.85