You are not logged in.
Pages: 1
I have one text file with the following content:
a
b
c
d
I have another text file with the following content:
A
B
C
D
How can I merge these two, such that the result is:
aA
bB
cC
dD
I could just open up excel and copy-paste, but that seems inelegant. I have both files open using gvim, but I am stumped as to how to go about this from there...
Any pointers would be highly appreciated!
Last edited by awayand (2012-01-04 07:20:35)
Offline
man join
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
man join
edit: too slow
Last edited by skunktrader (2012-01-04 07:14:40)
Offline
sweet! thanks!
Offline
In Python (named combine.py):
import sys
file1 = sys.argv[1]
file2 = sys.argv[2]
outfile = sys.argv[3]
f1 = open(file1,'r')
f2 = open(file2,'r')
lines1 = f1.readlines()
lines2 = f2.readlines()
f1.close()
f2.close()
outlines = zip(lines1, lines2)
of = open(outfile,'w')
for line in outlines:
of.write((line[0].strip('\n'))+(line[1].strip('\n'))+"\n")
of.close()
Usage:
python2 combine.py inputfile1 inputfile2 outputfile
Offline
I would have suggested
paste -d# file_1 file_2 | sed s/#//
Offline
I would have suggested
paste -d# file_1 file_2 | sed s/#//
paste -d "" file_1 file_2
is enough.
Offline
Pages: 1