I have two csv files.
File 1:
id,site,longitude,latitude
**9936**,north,18.2,62.8
5856,north,17.4914,63.0167
**1298**,north,18.177,62.877
File 2:
chr,loc,4678,**1298**,2295,**9936**,7354
chr1,849,0,0,0,0,0,
chr1,3481,1,1,0,1,1
chr1,3491,0,2,0,2,0,
I would like to match ids from column1 in file1 to rows in file2 (as highlighted with **
) and if the match print the row and the corresponding lines
Output:
chr,loc,**1298**,**9936**
chr1,849,0,0
chr1,3481,1,1
chr1,3491,0,2
I've been trying this in python
import csv
f1 = file('inFile.csv', 'rb')
f2 = file('inFile2.csv', 'rb')
f3 = file('outFile.csv', 'wb')
c1 = csv.reader(f1)
c2 = csv.reader(f2)
c3 = csv.writer(f3)
matched_rows = [ row for row in c2 if row[2:6] in c1]
for row in matched_rows:
c3writerow[matched_rows]
but unfortunately it doesn't work.