Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to join two CSV files?

same question I want to join 2 files 1st file column 1 2nbd file column 1

except that one of the csv files has variable no of columns in every record it has a traceroute from a certain Ip to a deifferent target everytime the join is based on the target IP it is the 1st column in both csv files

share|improve this question
does the other file have a fixed number of columns? –  datatoo May 24 '11 at 15:33
Can you give us a better description of what you want to accomplish? Your post is poorly formatted and doesn't state what you have and especially, what your desired output is. –  slhck May 24 '11 at 16:02

2 Answers 2

up vote 0 down vote accepted

Dont know I have read your question right. I would like to use the excellent csv module from python to do this.


file a


file b


Code - join.py

import csv
source1= csv.reader( open("a","rb") )
source2= csv.reader( open("b","rb") )
dest= csv.writer( open("c","wb") )
for row in source1:
for row in source2:
share|improve this answer
I don't think that's what the OP is looking for, I think he wants to join the second columns of each file based on a JOIN of the first columns. –  slhck May 24 '11 at 16:01

I would really use a database for this. You could try using MS Access or OpenOffice Base. You may need to use a spreadsheet (eg Excel) temporarily to help import the CSV files.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.