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.

I have a problem similar to the one mentioned here:

How to join two CSV files?

I awant to join the file, using the first field of both files as the join key.

The difference is that in one of the two files, the number of columns may vary from one record to another (it contains a traceroute, one ip per column, so the length may change.)

(The join key is the IP address, that is the first column in both 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.