0

I am trying to read data from 2 files and merging it to one csv file. However full data is not coming to the merged file (may be because of size limitations). Is there any way to deal with it

#!/usr/bin/env python
import re
import csv

f3 = open('/usr/tideway/sample/new/File1.csv','r').read()
f4 = open('/usr/tideway/sample/new/File2.csv','r').read()


f_out = open('/usr/tideway/sample/new/Merger.csv', 'w')
f_out.write(f3)
f_out.write(f4)
f_out.close()

Have also tried with csv module..but still the result is same

f3 = csv.reader(open('/usr/tideway/sample/new/File1.csv','r'), delimiter = ",")
f4 = csv.reader(open('/usr/tideway/sample/new/File2.csv','r'), delimiter = ",")

f5  = csv.writer(open('/usr/tideway/sample/new/Merger_new.csv', 'w'))
f5.writerows(f3)
f5.writerows(f4)

Any suggestion would be much helpful.

Rakesh
  • 23
  • 4
  • possible duplicate of [Python concatenate text files](http://stackoverflow.com/questions/13613336/python-concatenate-text-files) – Andrew Morton Sep 04 '15 at 08:07
  • Would you consider using other tools such as the "cat" command? You could merge files doing cat file1 file2 > filemerge . – Harald Sep 04 '15 at 08:09
  • Hi Andrew,,thank you for the response I have tried the following but the result is same... os.system("cat /usr/tideway/sample/new/File1.csv /usr/tideway/sample/new/File2.csv >mergercat.csv") But when I execute the cat command directly on the linux box I am getting full data into the merged file – Rakesh Sep 04 '15 at 09:17

0 Answers0